From e2615b57d4659ec320f69259db00ac34c31fb911 Mon Sep 17 00:00:00 2001 From: aliang Date: Thu, 19 Dec 2024 08:39:57 +0700 Subject: [PATCH] chore(ui): refresh notifications during revalidation (#3590) * chore(ui): refresh notifications during revalidation * update: config --- ee/tabby-ui/components/notification-box.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ee/tabby-ui/components/notification-box.tsx b/ee/tabby-ui/components/notification-box.tsx index f6c3fdabafec..19a37d04339c 100644 --- a/ee/tabby-ui/components/notification-box.tsx +++ b/ee/tabby-ui/components/notification-box.tsx @@ -3,6 +3,7 @@ import { HTMLAttributes, useMemo } from 'react' import { TabsContent } from '@radix-ui/react-tabs' import moment from 'moment' +import useSWR from 'swr' import { useQuery } from 'urql' import { graphql } from '@/lib/gql/generates' @@ -33,10 +34,17 @@ const markNotificationsReadMutation = graphql(/* GraphQL */ ` `) export function NotificationBox({ className, ...rest }: Props) { - const [{ data, fetching }] = useQuery({ + const [{ data, fetching }, reexecuteQuery] = useQuery({ query: notificationsQuery }) + useSWR('refresh_notifications', () => reexecuteQuery(), { + revalidateOnFocus: true, + revalidateOnReconnect: true, + revalidateOnMount: false, + refreshInterval: 1000 * 60 * 10 // 10 mins + }) + const notifications = useMemo(() => { return data?.notifications.slice().reverse() }, [data?.notifications])