diff --git a/src/pages/Config/TiddlyWiki.tsx b/src/pages/Config/TiddlyWiki.tsx index bd63597..8dea79a 100644 --- a/src/pages/Config/TiddlyWiki.tsx +++ b/src/pages/Config/TiddlyWiki.tsx @@ -2,13 +2,14 @@ import useDebouncedCallback from 'beautiful-react-hooks/useDebouncedCallback'; import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { Text, TextInput } from 'react-native-paper'; +import { Switch, Text, TextInput } from 'react-native-paper'; +import { FlexibleText, SwitchContainer } from '../../components/PreferenceWidgets'; import { useConfigStore } from '../../store/config'; export function TiddlyWiki(): JSX.Element { const { t } = useTranslation(); - const initialUserName = useConfigStore(state => state.userName); + const [initialUserName, rememberLastVisitState] = useConfigStore(state => [state.userName, state.rememberLastVisitState]); const [userName, userNameSetter] = useState(initialUserName); const setConfig = useConfigStore(state => state.set); @@ -26,6 +27,15 @@ export function TiddlyWiki(): JSX.Element { userNameTextFieldOnChange(newText); }} /> + + {t('Preference.RememberLastVisitState')} + { + setConfig({ rememberLastVisitState: value }); + }} + /> + ); } diff --git a/src/pages/WikiWebView/WikiViewer.tsx b/src/pages/WikiWebView/WikiViewer.tsx index 773b29d..0f16007 100644 --- a/src/pages/WikiWebView/WikiViewer.tsx +++ b/src/pages/WikiWebView/WikiViewer.tsx @@ -8,6 +8,7 @@ import { styled } from 'styled-components/native'; import { useRequestNativePermissions } from '../../services/NativeService/hooks'; import { useRegisterService } from '../../services/registerServiceOnWebView'; import { useSetWebViewReferenceToService } from '../../services/WikiHookService/hooks'; +import { useConfigStore } from '../../store/config'; import { IWikiWorkspace } from '../../store/wiki'; import { useStreamChunksToWebView } from './useStreamChunksToWebView'; import { onErrorHandler } from './useStreamChunksToWebView/onErrorHandler'; @@ -39,6 +40,7 @@ export const WikiViewer = ({ wikiWorkspace }: WikiViewerProps) => { const { t } = useTranslation(); const [loaded, setLoaded] = useState(false); + const [rememberLastVisitState] = useConfigStore(state => [state.rememberLastVisitState]); const [webViewReference, onMessageReference, registerWikiStorageServiceOnWebView, servicesOfWorkspace] = useRegisterService(wikiWorkspace); const [webViewKeyToReloadAfterRecycleByOS, setWebViewKeyToReloadAfterRecycleByOS] = useState(0); const triggerFullReload = () => { @@ -50,7 +52,7 @@ export const WikiViewer = ({ wikiWorkspace }: WikiViewerProps) => { const { loadHtmlError } = useTiddlyWiki(wikiWorkspace, injectHtmlAndTiddlersStore, loaded && webViewReference.current !== null, webViewKeyToReloadAfterRecycleByOS); const windowMetaScript = useWindowMeta(wikiWorkspace); const preloadScript = useMemo(() => ` - var lastLocationHash = \`${wikiWorkspace.lastLocationHash ?? ''}\`; + var lastLocationHash = \`${rememberLastVisitState ? wikiWorkspace.lastLocationHash ?? '' : ''}\`; location.hash = lastLocationHash; ${windowMetaScript} @@ -64,7 +66,7 @@ export const WikiViewer = ({ wikiWorkspace }: WikiViewerProps) => { ${webviewSideReceiver} true; // note: this is required, or you'll sometimes get silent failures - `, [registerWikiStorageServiceOnWebView, webviewSideReceiver, windowMetaScript]); + `, [registerWikiStorageServiceOnWebView, rememberLastVisitState, webviewSideReceiver, wikiWorkspace.lastLocationHash, windowMetaScript]); if (loadHtmlError) { return ( diff --git a/src/store/config.ts b/src/store/config.ts index 3973f98..2d2bdd5 100644 --- a/src/store/config.ts +++ b/src/store/config.ts @@ -7,6 +7,7 @@ export interface ConfigState { autoOpenDefaultWiki: boolean; keepAliveInBackground: boolean; preferredLanguage?: string; + rememberLastVisitState: boolean; syncInBackground: boolean; syncInterval: number; syncIntervalBackground: number; @@ -14,6 +15,7 @@ export interface ConfigState { } const defaultConfig: ConfigState = { autoOpenDefaultWiki: true, + rememberLastVisitState: true, keepAliveInBackground: true, syncInBackground: true, preferredLanguage: undefined,