Fix background location need to persist
This commit is contained in:
parent
4f91d9e4e9
commit
ddce5bb0ff
1 changed files with 16 additions and 6 deletions
22
src/app.jsx
22
src/app.jsx
|
@ -3,7 +3,13 @@ import 'toastify-js/src/toastify.css';
|
||||||
|
|
||||||
import debounce from 'just-debounce-it';
|
import debounce from 'just-debounce-it';
|
||||||
import { login } from 'masto';
|
import { login } from 'masto';
|
||||||
import { useEffect, useLayoutEffect, useMemo, useState } from 'preact/hooks';
|
import {
|
||||||
|
useEffect,
|
||||||
|
useLayoutEffect,
|
||||||
|
useMemo,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
} from 'preact/hooks';
|
||||||
import { Route, Routes, useLocation, useNavigate } from 'react-router-dom';
|
import { Route, Routes, useLocation, useNavigate } from 'react-router-dom';
|
||||||
import Toastify from 'toastify-js';
|
import Toastify from 'toastify-js';
|
||||||
import { useSnapshot } from 'valtio';
|
import { useSnapshot } from 'valtio';
|
||||||
|
@ -176,15 +182,19 @@ function App() {
|
||||||
}
|
}
|
||||||
}, [isLoggedIn]);
|
}, [isLoggedIn]);
|
||||||
|
|
||||||
const backgroundLocation = useMemo(() => {
|
const backgroundLocation = useRef();
|
||||||
|
useEffect(() => {
|
||||||
const { prevLocation } = snapStates;
|
const { prevLocation } = snapStates;
|
||||||
|
|
||||||
console.debug({ location, prevLocation });
|
|
||||||
const { pathname } = location;
|
const { pathname } = location;
|
||||||
const { pathname: prevPathname } = prevLocation || {};
|
const { pathname: prevPathname } = prevLocation || {};
|
||||||
console.debug({ prevPathname, pathname });
|
console.debug({ prevPathname, pathname });
|
||||||
const isModalPage = /^\/s\//i.test(pathname);
|
const isModalPage = /^\/s\//i.test(pathname);
|
||||||
return isModalPage ? prevLocation : null;
|
if (isModalPage) {
|
||||||
|
if (!backgroundLocation.current)
|
||||||
|
backgroundLocation.current = prevLocation;
|
||||||
|
} else {
|
||||||
|
backgroundLocation.current = null;
|
||||||
|
}
|
||||||
}, [location]);
|
}, [location]);
|
||||||
|
|
||||||
const nonRootLocation = useMemo(() => {
|
const nonRootLocation = useMemo(() => {
|
||||||
|
@ -210,7 +220,7 @@ function App() {
|
||||||
<Route path="/login" element={<Login />} />
|
<Route path="/login" element={<Login />} />
|
||||||
<Route path="/welcome" element={<Welcome />} />
|
<Route path="/welcome" element={<Welcome />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
<Routes location={backgroundLocation || location}>
|
<Routes location={backgroundLocation.current || location}>
|
||||||
{isLoggedIn && (
|
{isLoggedIn && (
|
||||||
<Route path="/notifications" element={<Notifications />} />
|
<Route path="/notifications" element={<Notifications />} />
|
||||||
)}
|
)}
|
||||||
|
|
Loading…
Add table
Reference in a new issue