From 1831d291f1a9ee481c5aa7f999fc5abb91efa6f2 Mon Sep 17 00:00:00 2001 From: CatsJuice Date: Wed, 21 May 2025 03:04:01 +0000 Subject: [PATCH] feat(core): duplicated calendar subscription notification (#12364) --- .../integration/calendar/setting-panel.tsx | 13 ++++++++++++- .../src/modules/integration/entities/calendar.ts | 4 ++++ .../core/src/modules/integration/store/calendar.ts | 4 ++++ packages/frontend/i18n/src/i18n.gen.ts | 8 ++++++++ packages/frontend/i18n/src/resources/en.json | 2 ++ 5 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/frontend/core/src/desktop/dialogs/setting/workspace-setting/integration/calendar/setting-panel.tsx b/packages/frontend/core/src/desktop/dialogs/setting/workspace-setting/integration/calendar/setting-panel.tsx index 3aec8fdac..30b22f221 100644 --- a/packages/frontend/core/src/desktop/dialogs/setting/workspace-setting/integration/calendar/setting-panel.tsx +++ b/packages/frontend/core/src/desktop/dialogs/setting/workspace-setting/integration/calendar/setting-panel.tsx @@ -55,9 +55,20 @@ const AddSubscription = () => { }, []); const handleAddSub = useCallback(() => { + const _url = url.trim(); + const exists = calendar.getSubscription(_url); + if (exists) { + notify.error({ + title: t['com.affine.integration.calendar.new-duplicate-error-title'](), + message: + t['com.affine.integration.calendar.new-duplicate-error-content'](), + }); + return; + } + setVerifying(true); calendar - .createSubscription(url) + .createSubscription(_url) .then(() => { setOpen(false); setUrl(''); diff --git a/packages/frontend/core/src/modules/integration/entities/calendar.ts b/packages/frontend/core/src/modules/integration/entities/calendar.ts index 8d9e432bc..89bea2e0f 100644 --- a/packages/frontend/core/src/modules/integration/entities/calendar.ts +++ b/packages/frontend/core/src/modules/integration/entities/calendar.ts @@ -106,6 +106,10 @@ export class CalendarIntegration extends Entity { } } + getSubscription(url: string) { + return this.store.getSubscription(url); + } + deleteSubscription(url: string) { this.store.removeSubscription(url); } diff --git a/packages/frontend/core/src/modules/integration/store/calendar.ts b/packages/frontend/core/src/modules/integration/store/calendar.ts index 0cb78234e..2cce49c06 100644 --- a/packages/frontend/core/src/modules/integration/store/calendar.ts +++ b/packages/frontend/core/src/modules/integration/store/calendar.ts @@ -99,6 +99,10 @@ export class CalendarStore extends Store { ); } + getSubscription(url: string) { + return this.getSubscriptionMap()[url]; + } + watchSubscriptionCache(url: string) { return this.cacheStorage.watch(this.getCacheKey(url)); } diff --git a/packages/frontend/i18n/src/i18n.gen.ts b/packages/frontend/i18n/src/i18n.gen.ts index 7707beb35..d8f8ea618 100644 --- a/packages/frontend/i18n/src/i18n.gen.ts +++ b/packages/frontend/i18n/src/i18n.gen.ts @@ -7906,6 +7906,14 @@ export function useAFFiNEI18N(): { * `Calendar URL` */ ["com.affine.integration.calendar.new-url-label"](): string; + /** + * `This is a duplicate calendar` + */ + ["com.affine.integration.calendar.new-duplicate-error-title"](): string; + /** + * `This subscription calendar already exists in the account of subscribed calendars.` + */ + ["com.affine.integration.calendar.new-duplicate-error-content"](): string; /** * `An error occurred while adding the calendar` */ diff --git a/packages/frontend/i18n/src/resources/en.json b/packages/frontend/i18n/src/resources/en.json index edf0cd700..a9fe645e0 100644 --- a/packages/frontend/i18n/src/resources/en.json +++ b/packages/frontend/i18n/src/resources/en.json @@ -1979,6 +1979,8 @@ "com.affine.integration.calendar.unsubscribe": "Unsubscribe", "com.affine.integration.calendar.new-title": "Add a calendar by URL", "com.affine.integration.calendar.new-url-label": "Calendar URL", + "com.affine.integration.calendar.new-duplicate-error-title": "This is a duplicate calendar", + "com.affine.integration.calendar.new-duplicate-error-content": "This subscription calendar already exists in the account of subscribed calendars.", "com.affine.integration.calendar.new-error": "An error occurred while adding the calendar", "com.affine.integration.calendar.all-day": "All day", "com.affine.integration.calendar.new-doc": "New doc",