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 2 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
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.delete == true))
magnusrand marked this conversation as resolved.
Show resolved Hide resolved

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
32 changes: 18 additions & 14 deletions src/services/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,26 +150,30 @@ 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().delete == true) {
magnusrand marked this conversation as resolved.
Show resolved Hide resolved
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> =>
Expand Down
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[]
delete?: boolean
magnusrand marked this conversation as resolved.
Show resolved Hide resolved
}

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