Skip to content
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

Improve custom url backend #499

Merged
merged 3 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
9 changes: 8 additions & 1 deletion src/containers/MyBoards/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ function sortBoard(boards: BoardProps[]): BoardProps[] {
})
}

const filterBoards = (boards: BoardProps[]): BoardProps[] =>
boards.filter((board) => !board.data.isScheduledForDelete)

const MyBoards = ({ history }: Props): JSX.Element | null => {
const [boards, setBoards] = useState<DocumentData>()
const user = useUser()
Expand All @@ -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([]),
})
Expand Down
34 changes: 19 additions & 15 deletions src/services/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,27 +150,31 @@ export const uploadLogo = async (
)
}

export const copySettingsToNewId = (
export const copySettingsToNewId = async (
newDocId: string,
settings: Settings | null,
): Promise<boolean> => {
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().isScheduledForDelete) {
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<void> =>
updateSingleSettingsField(docId, 'delete', true)
updateSingleSettingsField(docId, 'isScheduledForDelete', true)
1 change: 1 addition & 0 deletions src/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface Settings {
hideWalkInfo?: boolean
hideRealtimeData?: boolean
hiddenRealtimeDataLineRefs: string[]
isScheduledForDelete?: boolean
}

type Setter = (settings: Partial<Settings>) => void
Expand Down