feat: fix refresh

This commit is contained in:
Kalidou Diagne
2025-03-13 20:05:12 +00:00
parent a79331596e
commit 029965cf0e
2 changed files with 15 additions and 4 deletions

View File

@@ -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">

View File

@@ -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()),
}
}