Skip to content

Commit

Permalink
Merge pull request #55526 from daledah/fix/55085
Browse files Browse the repository at this point in the history
fix: show not found page when open invalid room link
  • Loading branch information
nkuoch authored Jan 28, 2025
2 parents 0e13adf + ef7234c commit b9aa851
Showing 1 changed file with 39 additions and 32 deletions.
71 changes: 39 additions & 32 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
const isFocused = useIsFocused();
const prevIsFocused = usePrevious(isFocused);
const firstRenderRef = useRef(true);
const [firstRender, setFirstRender] = useState(true);
const isSkippingOpenReport = useRef(false);
const flatListRef = useRef<FlatList>(null);
const {canUseDefaultRooms} = usePermissions();
Expand Down Expand Up @@ -431,43 +432,48 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
const currentReportIDFormRoute = route.params?.reportID;

// eslint-disable-next-line rulesdir/no-negated-variables
const shouldShowNotFoundPage = useMemo((): boolean => {
if (shouldShowNotFoundLinkedAction) {
return true;
}
const shouldShowNotFoundPage = useMemo(
(): boolean => {
if (shouldShowNotFoundLinkedAction) {
return true;
}

// Wait until we're sure the app is done loading (needs to be a strict equality check since it's undefined initially)
if (isLoadingApp !== false) {
return false;
}
// Wait until we're sure the app is done loading (needs to be a strict equality check since it's undefined initially)
if (isLoadingApp !== false) {
return false;
}

// If we just finished loading the app, we still need to try fetching the report. Wait until that's done before
// showing the Not Found page
if (finishedLoadingApp) {
return false;
}
// If we just finished loading the app, we still need to try fetching the report. Wait until that's done before
// showing the Not Found page
if (finishedLoadingApp) {
return false;
}

// eslint-disable-next-line react-compiler/react-compiler
if (!wasReportAccessibleRef.current && !firstRenderRef.current && !reportID && !isOptimisticDelete && !reportMetadata?.isLoadingInitialReportActions && !userLeavingStatus) {
// eslint-disable-next-line react-compiler/react-compiler
return true;
}
if (!wasReportAccessibleRef.current && !firstRenderRef.current && !reportID && !isOptimisticDelete && !reportMetadata?.isLoadingInitialReportActions && !userLeavingStatus) {
// eslint-disable-next-line react-compiler/react-compiler
return true;
}

if (shouldHideReport) {
return true;
}
return !!currentReportIDFormRoute && !isValidReportIDFromPath(currentReportIDFormRoute);
}, [
shouldShowNotFoundLinkedAction,
isLoadingApp,
finishedLoadingApp,
reportID,
isOptimisticDelete,
reportMetadata?.isLoadingInitialReportActions,
userLeavingStatus,
shouldHideReport,
currentReportIDFormRoute,
]);
if (shouldHideReport) {
return true;
}
return !!currentReportIDFormRoute && !isValidReportIDFromPath(currentReportIDFormRoute);
},
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
[
firstRender,
shouldShowNotFoundLinkedAction,
isLoadingApp,
finishedLoadingApp,
reportID,
isOptimisticDelete,
reportMetadata?.isLoadingInitialReportActions,
userLeavingStatus,
shouldHideReport,
currentReportIDFormRoute,
],
);

const fetchReport = useCallback(() => {
openReport(reportIDFromRoute, reportActionIDFromRoute);
Expand Down Expand Up @@ -600,6 +606,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
// We don't want this effect to run on the first render.
if (firstRenderRef.current) {
firstRenderRef.current = false;
setFirstRender(false);
return;
}

Expand Down

0 comments on commit b9aa851

Please sign in to comment.