fix: hopefully fix jumping pages when there's cached data
This commit is contained in:
parent
b30d90319e
commit
1ce4115fb1
1 changed files with 7 additions and 1 deletions
|
@ -29,19 +29,24 @@ function ShoutboxInner(props: {
|
||||||
}) {
|
}) {
|
||||||
// eslint-disable-next-line solid/reactivity
|
// eslint-disable-next-line solid/reactivity
|
||||||
const [page, setPage] = createSignal(props.initPage)
|
const [page, setPage] = createSignal(props.initPage)
|
||||||
|
// eslint-disable-next-line solid/reactivity
|
||||||
|
const [initData, setInitData] = createSignal<ShoutsData | undefined>(props.initPageData)
|
||||||
|
|
||||||
const shouts = createQuery(() => ({
|
const shouts = createQuery(() => ({
|
||||||
queryKey: ['shouts', page()],
|
queryKey: ['shouts', page()],
|
||||||
queryFn: () => fetchShouts(page()),
|
queryFn: () => fetchShouts(page()),
|
||||||
|
cacheTime: 0,
|
||||||
|
gcTime: 0,
|
||||||
refetchInterval: 30000,
|
refetchInterval: 30000,
|
||||||
placeholderData: keepPreviousData,
|
placeholderData: keepPreviousData,
|
||||||
initialData: props.initPageData,
|
initialData: initData,
|
||||||
}))
|
}))
|
||||||
const [sending, setSending] = createSignal(false)
|
const [sending, setSending] = createSignal(false)
|
||||||
|
|
||||||
const onPageClick = (next: boolean) => (e: MouseEvent) => {
|
const onPageClick = (next: boolean) => (e: MouseEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
|
setInitData(undefined)
|
||||||
|
|
||||||
const newPage = next ? page() + 1 : page() - 1
|
const newPage = next ? page() + 1 : page() - 1
|
||||||
|
|
||||||
|
@ -89,6 +94,7 @@ function ShoutboxInner(props: {
|
||||||
const onSubmit = (e: Event) => {
|
const onSubmit = (e: Event) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
setSending(true)
|
setSending(true)
|
||||||
|
setInitData(undefined)
|
||||||
|
|
||||||
const isPrivate = (form.elements.namedItem('private') as HTMLInputElement).checked
|
const isPrivate = (form.elements.namedItem('private') as HTMLInputElement).checked
|
||||||
fetch('/api/shoutbox', {
|
fetch('/api/shoutbox', {
|
||||||
|
|
Loading…
Reference in a new issue