Skip to content

Commit

Permalink
fix: make sure to not show confirmed alert until document has loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
thoreyjona committed Sep 30, 2024
1 parent 6cc110e commit c48ef68
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions apps/native/app/src/screens/document-detail/document-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ export const DocumentDetailScreen: NavigationFunctionComponent<{
const [visible, setVisible] = useState(false)
const [loaded, setLoaded] = useState(false)
const [pdfUrl, setPdfUrl] = useState('')
const [refetching, setRefetching] = useState(false)

// Check if we have the document in the cache
const doc = useFragment_experimental<DocumentV2>({
Expand All @@ -258,7 +259,7 @@ export const DocumentDetailScreen: NavigationFunctionComponent<{
fetchPolicy: 'no-cache',
onCompleted: (data) => {
const confirmation = data.documentV2?.confirmation
if (confirmation && !showConfirmedAlert) {
if (confirmation && !refetching && !showConfirmedAlert) {
RNAlert.alert(confirmation.title ?? '', confirmation.data ?? '', [
{
text: intl.formatMessage({
Expand All @@ -274,12 +275,17 @@ export const DocumentDetailScreen: NavigationFunctionComponent<{
id: 'inbox.openDocument',
}),
onPress: async () => {
docRes.refetch({
input: { id: docId, includeDocument: true },
})
if (data.documentV2?.alert) {
setShowConfirmedAlert(true)
}
setRefetching(true)
docRes
.refetch({
input: { id: docId, includeDocument: true },
})
.then(() => {
if (data.documentV2?.alert) {
setShowConfirmedAlert(true)
}
})
.finally(() => setRefetching(false))
},
},
])
Expand Down

0 comments on commit c48ef68

Please sign in to comment.