mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 02:14:05 +00:00
feat(pwa): reopen the trip and tab the installed app was in (#1024)
This commit is contained in:
@@ -23,6 +23,7 @@ import { TranslationProvider, useTranslation } from './i18n'
|
||||
import { authApi, isAuthPublicPath } from './api/client'
|
||||
import { tripRepo } from './repo/tripRepo'
|
||||
import { readStartDestination, tripStartPath, DEFAULT_START_PAGE, DEFAULT_START_TRIP_TAB, SETTINGS_WAIT_MS, START_DESTINATION_ROUTE } from './utils/startDestination'
|
||||
import { takeResumeRoute, useRememberRoute } from './utils/resumeRoute'
|
||||
import { usePermissionsStore, PermissionLevel } from './store/permissionsStore'
|
||||
import { useInAppNotificationListener } from './hooks/useInAppNotificationListener.ts'
|
||||
import { useRoadtripPreferencesSync } from './hooks/useRoadtripPreferencesSync'
|
||||
@@ -144,6 +145,7 @@ function ProtectedRoute({ children, adminRequired = false, addonId }: ProtectedR
|
||||
// instance across a navigation and the error would follow the user around.
|
||||
return (
|
||||
<MobileShell isPhone={isPhone}>
|
||||
<RouteMemory />
|
||||
<ErrorBoundary
|
||||
key={location.pathname}
|
||||
boundaryId="route"
|
||||
@@ -214,6 +216,12 @@ function ViewportRoute({ phone: Phone, desktop: Desktop }: {
|
||||
* didn't set it. Only 'active_trip' costs the one lookup that finds the trip,
|
||||
* and any failure along the way lands on the dashboard.
|
||||
*/
|
||||
/** Remembers the protected route for the installed app's relaunch (#1024). Renders nothing. */
|
||||
function RouteMemory() {
|
||||
useRememberRoute()
|
||||
return null
|
||||
}
|
||||
|
||||
function RootRedirect() {
|
||||
const { isAuthenticated, isLoading } = useAuthStore()
|
||||
const settingsLoaded = useSettingsStore((s) => s.isLoaded)
|
||||
@@ -233,6 +241,10 @@ function RootRedirect() {
|
||||
|
||||
useEffect(() => {
|
||||
if (isLoading || !isAuthenticated || target) return
|
||||
// The installed app coming back after the system threw it away (#1024):
|
||||
// back to the trip and tab it was in, ahead of the start page.
|
||||
const resume = takeResumeRoute()
|
||||
if (resume) { setTarget(resume); return }
|
||||
const mirrored = readStartDestination()
|
||||
if (!mirrored && !settingsLoaded && !settingsGaveUp) {
|
||||
// Ask for the settings instead of waiting for whoever else might. The
|
||||
|
||||
Reference in New Issue
Block a user