-
Notifications
You must be signed in to change notification settings - Fork 23
feat: add clear notification history feature #239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: api-v2
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,45 @@ | ||||||
| import useSWRMutation from 'swr/mutation'; | ||||||
| import { useDialectContext } from '../context'; | ||||||
| import { getRequestHeaders } from './internal/api-v2-helpers'; | ||||||
| import { CACHE_KEY_READ_MUTATION } from './internal/swrCache'; | ||||||
| import useDialectSdk from './useDialectSdk'; | ||||||
|
|
||||||
| export default function useClearHistory() { | ||||||
| const { | ||||||
| clientKey, | ||||||
| app: { id: appId }, | ||||||
| } = useDialectContext(); | ||||||
| const sdk = useDialectSdk(); | ||||||
|
|
||||||
| const { trigger, isMutating, error } = useSWRMutation( | ||||||
| appId && clientKey ? CACHE_KEY_READ_MUTATION(appId) : null, | ||||||
| async () => { | ||||||
| if (!appId || !clientKey) { | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| const response = await fetch( | ||||||
| `${sdk.config.dialectCloud.v2Url}/v2/history/clear`, | ||||||
| { | ||||||
| method: 'POST', | ||||||
| body: JSON.stringify({ | ||||||
| appId, | ||||||
| }), | ||||||
| headers: await getRequestHeaders(sdk, clientKey), | ||||||
| }, | ||||||
| ); | ||||||
|
|
||||||
| if (!response.ok) { | ||||||
| throw await response.json(); | ||||||
| } | ||||||
|
|
||||||
| return response.json() as Promise<void>; | ||||||
|
||||||
| return response.json() as Promise<void>; | |
| return response.json(); |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,19 +1,26 @@ | ||||||||||||||
| import { useClearHistory, useHistory } from '@dialectlabs/react-sdk'; | ||||||||||||||
| import { Header } from '../../core'; | ||||||||||||||
| import { useExternalProps } from '../internal/ExternalPropsProvider'; | ||||||||||||||
| import { Route, useRouter } from '../internal/Router'; | ||||||||||||||
|
|
||||||||||||||
| export const NotificationsFeedHeader = () => { | ||||||||||||||
| const { setOpen } = useExternalProps(); | ||||||||||||||
| const { setRoute } = useRouter(); | ||||||||||||||
| const { clear } = useClearHistory(); | ||||||||||||||
| const { refresh } = useHistory(); | ||||||||||||||
|
|
||||||||||||||
| return ( | ||||||||||||||
| <Header | ||||||||||||||
| title="Notifications" | ||||||||||||||
| showBackButton={false} | ||||||||||||||
| showSettingsButton={true} | ||||||||||||||
| showCloseButton={!!setOpen} | ||||||||||||||
| showClearNotificationsButton={true} | ||||||||||||||
| onSettingsClick={() => setRoute(Route.Settings)} | ||||||||||||||
| onCloseClick={() => setOpen?.(false)} | ||||||||||||||
| onClearNotificationsClick={() => { | ||||||||||||||
| clear().then(() => refresh()); | ||||||||||||||
|
||||||||||||||
| clear().then(() => refresh()); | |
| clear() | |
| .then(() => refresh()) | |
| .catch((err) => { | |
| console.error('Failed to clear notifications:', err); | |
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please create a separate key for history clear mutation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed that, added a new fix commit