fix(settings): preserve notification template edits (#2300)
This commit is contained in:
@@ -152,13 +152,13 @@ export const NotificationSettings: React.FC = () => {
|
|||||||
field: 'title' | 'message',
|
field: 'title' | 'message',
|
||||||
value: string,
|
value: string,
|
||||||
) => {
|
) => {
|
||||||
setNotificationTemplates({
|
setNotificationTemplates((current) => ({
|
||||||
...notificationTemplates,
|
...current,
|
||||||
[event]: {
|
[event]: {
|
||||||
...notificationTemplates[event],
|
...current[event],
|
||||||
[field]: value,
|
[field]: value,
|
||||||
},
|
},
|
||||||
});
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const base64UrlToUint8Array = (base64Url: string): Uint8Array<ArrayBuffer> => {
|
const base64UrlToUint8Array = (base64Url: string): Uint8Array<ArrayBuffer> => {
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import { afterEach, describe, expect, test } from 'bun:test';
|
||||||
|
import { useUIStore } from './useUIStore';
|
||||||
|
|
||||||
|
const initialTemplates = useUIStore.getState().notificationTemplates;
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
useUIStore.setState({ notificationTemplates: initialTemplates });
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('useUIStore notification templates', () => {
|
||||||
|
test('preserves rapid updates to separate template fields', () => {
|
||||||
|
const { setNotificationTemplates } = useUIStore.getState();
|
||||||
|
|
||||||
|
setNotificationTemplates((current) => ({
|
||||||
|
...current,
|
||||||
|
completion: { ...current.completion, title: 'Completed' },
|
||||||
|
}));
|
||||||
|
setNotificationTemplates((current) => ({
|
||||||
|
...current,
|
||||||
|
error: { ...current.error, message: 'Failed' },
|
||||||
|
}));
|
||||||
|
|
||||||
|
expect(useUIStore.getState().notificationTemplates).toEqual({
|
||||||
|
...initialTemplates,
|
||||||
|
completion: { ...initialTemplates.completion, title: 'Completed' },
|
||||||
|
error: { ...initialTemplates.error, message: 'Failed' },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -842,7 +842,9 @@ interface UIStore {
|
|||||||
setNotifyOnCompletion: (value: boolean) => void;
|
setNotifyOnCompletion: (value: boolean) => void;
|
||||||
setNotifyOnError: (value: boolean) => void;
|
setNotifyOnError: (value: boolean) => void;
|
||||||
setNotifyOnQuestion: (value: boolean) => void;
|
setNotifyOnQuestion: (value: boolean) => void;
|
||||||
setNotificationTemplates: (templates: UIStore['notificationTemplates']) => void;
|
setNotificationTemplates: (
|
||||||
|
templates: UIStore['notificationTemplates'] | ((current: UIStore['notificationTemplates']) => UIStore['notificationTemplates']),
|
||||||
|
) => void;
|
||||||
setSummarizeLastMessage: (value: boolean) => void;
|
setSummarizeLastMessage: (value: boolean) => void;
|
||||||
setSummaryThreshold: (value: number) => void;
|
setSummaryThreshold: (value: number) => void;
|
||||||
setSummaryLength: (value: number) => void;
|
setSummaryLength: (value: number) => void;
|
||||||
@@ -2135,7 +2137,13 @@ export const useUIStore = create<UIStore>()(
|
|||||||
setNotifyOnCompletion: (value) => { set({ notifyOnCompletion: value }); },
|
setNotifyOnCompletion: (value) => { set({ notifyOnCompletion: value }); },
|
||||||
setNotifyOnError: (value) => { set({ notifyOnError: value }); },
|
setNotifyOnError: (value) => { set({ notifyOnError: value }); },
|
||||||
setNotifyOnQuestion: (value) => { set({ notifyOnQuestion: value }); },
|
setNotifyOnQuestion: (value) => { set({ notifyOnQuestion: value }); },
|
||||||
setNotificationTemplates: (templates) => { set({ notificationTemplates: templates }); },
|
setNotificationTemplates: (templates) => {
|
||||||
|
set((state) => ({
|
||||||
|
notificationTemplates: typeof templates === 'function'
|
||||||
|
? templates(state.notificationTemplates)
|
||||||
|
: templates,
|
||||||
|
}));
|
||||||
|
},
|
||||||
setSummarizeLastMessage: (value) => { set({ summarizeLastMessage: value }); },
|
setSummarizeLastMessage: (value) => { set({ summarizeLastMessage: value }); },
|
||||||
setSummaryThreshold: (value) => { set({ summaryThreshold: value }); },
|
setSummaryThreshold: (value) => { set({ summaryThreshold: value }); },
|
||||||
setSummaryLength: (value) => { set({ summaryLength: value }); },
|
setSummaryLength: (value) => { set({ summaryLength: value }); },
|
||||||
|
|||||||
Reference in New Issue
Block a user