From 44800e62bbae69b82b473e30fd31b779fea1d2cb Mon Sep 17 00:00:00 2001 From: Magnus Rand Date: Thu, 21 Oct 2021 11:33:31 +0200 Subject: [PATCH 1/3] Make TavleIDs set to delete available as customURL --- src/services/firebase.ts | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/services/firebase.ts b/src/services/firebase.ts index 54095f37b..109ea020d 100644 --- a/src/services/firebase.ts +++ b/src/services/firebase.ts @@ -150,26 +150,30 @@ export const uploadLogo = async ( ) } -export const copySettingsToNewId = ( +export const copySettingsToNewId = async ( newDocId: string, settings: Settings | null, ): Promise => { + if (!settings) return false + const newDocRef: DocumentReference = getSettings(newDocId) - return getDoc(newDocRef) - .then((document) => { - if (document.exists()) { - return false - } else { - if (settings) { - createSettingsWithId(settings, newDocId) - return true - } else { - return false - } + try { + const document = await getDoc(newDocRef) + if (document.exists()) { + if (document.data().delete == true) { + await deleteDoc(newDocRef) + await createSettingsWithId(settings, newDocId) + return true } - }) - .catch(() => false) + return false + } else { + await createSettingsWithId(settings, newDocId) + return true + } + } catch { + return false + } } export const setIdToBeDeleted = (docId: string): Promise => From 6e23039fda2323b03599bc324e4fa08b163580cc Mon Sep 17 00:00:00 2001 From: Magnus Rand Date: Thu, 21 Oct 2021 14:01:58 +0200 Subject: [PATCH 2/3] filter out boards set to be deleted --- src/containers/MyBoards/index.tsx | 9 ++++++++- src/settings/index.ts | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/containers/MyBoards/index.tsx b/src/containers/MyBoards/index.tsx index f24c31670..ce7918f6d 100644 --- a/src/containers/MyBoards/index.tsx +++ b/src/containers/MyBoards/index.tsx @@ -28,6 +28,9 @@ function sortBoard(boards: BoardProps[]): BoardProps[] { }) } +const filterBoards = (boards: BoardProps[]): BoardProps[] => + boards.filter((board) => !(board.data.delete == true)) + const MyBoards = ({ history }: Props): JSX.Element | null => { const [boards, setBoards] = useState() const user = useUser() @@ -51,7 +54,11 @@ const MyBoards = ({ history }: Props): JSX.Element | null => { id: docSnapshot.id, } as BoardProps), ) - setBoards(updatedBoards.length ? sortBoard(updatedBoards) : []) + setBoards( + updatedBoards.length + ? sortBoard(filterBoards(updatedBoards)) + : [], + ) }, error: () => setBoards([]), }) diff --git a/src/settings/index.ts b/src/settings/index.ts index 33f1837f1..b1f961d1e 100644 --- a/src/settings/index.ts +++ b/src/settings/index.ts @@ -62,6 +62,7 @@ export interface Settings { hideWalkInfo?: boolean hideRealtimeData?: boolean hiddenRealtimeDataLineRefs: string[] + delete?: boolean } type Setter = (settings: Partial) => void From 89d4fc3ff0b016f5fe535ee7d3244ede1f21ee8d Mon Sep 17 00:00:00 2001 From: Magnus Rand Date: Mon, 25 Oct 2021 14:53:05 +0200 Subject: [PATCH 3/3] =?UTF-8?q?Change=20=C2=B4delete=C2=B4=20setting=20fie?= =?UTF-8?q?ld=20to=20=C2=B4isScheduledForDelete=C2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions/src/index.ts | 2 +- src/containers/MyBoards/index.tsx | 2 +- src/services/firebase.ts | 4 ++-- src/settings/index.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/functions/src/index.ts b/functions/src/index.ts index 50d4f2ef7..6a4d882cf 100644 --- a/functions/src/index.ts +++ b/functions/src/index.ts @@ -81,7 +81,7 @@ export const scheduledDeleteOfDocumentsSetToBeDeleted = region('us-central1') const batch = firestore().batch() firestore() .collection('settings') - .where('delete', '==', true) + .where('isScheduledForDelete', '==', true) .get() .then((querySnapshot) => { querySnapshot.forEach((doc) => { diff --git a/src/containers/MyBoards/index.tsx b/src/containers/MyBoards/index.tsx index ce7918f6d..750818f44 100644 --- a/src/containers/MyBoards/index.tsx +++ b/src/containers/MyBoards/index.tsx @@ -29,7 +29,7 @@ function sortBoard(boards: BoardProps[]): BoardProps[] { } const filterBoards = (boards: BoardProps[]): BoardProps[] => - boards.filter((board) => !(board.data.delete == true)) + boards.filter((board) => !board.data.isScheduledForDelete) const MyBoards = ({ history }: Props): JSX.Element | null => { const [boards, setBoards] = useState() diff --git a/src/services/firebase.ts b/src/services/firebase.ts index 109ea020d..b5c1910f0 100644 --- a/src/services/firebase.ts +++ b/src/services/firebase.ts @@ -161,7 +161,7 @@ export const copySettingsToNewId = async ( try { const document = await getDoc(newDocRef) if (document.exists()) { - if (document.data().delete == true) { + if (document.data().isScheduledForDelete) { await deleteDoc(newDocRef) await createSettingsWithId(settings, newDocId) return true @@ -177,4 +177,4 @@ export const copySettingsToNewId = async ( } export const setIdToBeDeleted = (docId: string): Promise => - updateSingleSettingsField(docId, 'delete', true) + updateSingleSettingsField(docId, 'isScheduledForDelete', true) diff --git a/src/settings/index.ts b/src/settings/index.ts index b1f961d1e..6000e98e0 100644 --- a/src/settings/index.ts +++ b/src/settings/index.ts @@ -62,7 +62,7 @@ export interface Settings { hideWalkInfo?: boolean hideRealtimeData?: boolean hiddenRealtimeDataLineRefs: string[] - delete?: boolean + isScheduledForDelete?: boolean } type Setter = (settings: Partial) => void