mirror of
https://github.com/privacy-scaling-explorations/pse.dev.git
synced 2026-04-23 03:01:03 -04:00
feat: fix refresh
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useTranslation } from '@/app/i18n/client'
|
||||
import { Icons } from '@/components/icons'
|
||||
import { Button } from '@/components/ui/button'
|
||||
@@ -33,8 +33,15 @@ export default function EventsPage({
|
||||
params: { lang: string }
|
||||
}) {
|
||||
const [viewMode, setViewMode] = useState<ViewMode>('list')
|
||||
const { data: { events, page } = { events: [], page: {} }, isLoading } =
|
||||
useGetNotionEvents()
|
||||
const {
|
||||
data: { events, page } = { events: [], page: {} },
|
||||
isLoading,
|
||||
refresh,
|
||||
} = useGetNotionEvents()
|
||||
|
||||
useEffect(() => {
|
||||
refresh()
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div className="flex flex-col">
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { EventProps } from '@/app/[lang]/events/page'
|
||||
import useSWR from 'swr'
|
||||
import { useState } from 'react'
|
||||
|
||||
const fetcher = async (url: string) => {
|
||||
const response = await fetch(url, {
|
||||
@@ -15,8 +16,10 @@ const fetcher = async (url: string) => {
|
||||
}
|
||||
|
||||
export function useGetNotionEvents() {
|
||||
const [forceRefresh, setForceRefresh] = useState(0)
|
||||
|
||||
const { data, error } = useSWR<{ events: EventProps['event'][]; page: any }>(
|
||||
`/api/events?timestamp=${Date.now()}`,
|
||||
`/api/events?refresh=${forceRefresh}`,
|
||||
fetcher,
|
||||
{
|
||||
refreshInterval: 60000,
|
||||
@@ -32,5 +35,6 @@ export function useGetNotionEvents() {
|
||||
: { events: [], page: {} },
|
||||
isLoading: !data && !error,
|
||||
error,
|
||||
refresh: () => setForceRefresh(Date.now()),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user