Compare commits

...

2 commits

Author SHA1 Message Date
thislight
3b5cc1e64e
StackedRouter: fix backward does not pop page 2024-11-18 18:32:06 +08:00
thislight
00554a045f
Settings: minor cleanup 2024-11-18 18:12:32 +08:00
2 changed files with 16 additions and 28 deletions

View file

@ -194,11 +194,13 @@ function animateOpen(element: HTMLElement) {
function serializableStack(stack: readonly StackFrame[]) { function serializableStack(stack: readonly StackFrame[]) {
const frames = unwrap(stack); const frames = unwrap(stack);
return frames.map((fr) => { return frames.map((fr) => {
return { return fr.animateClose || fr.animateOpen
path: fr.path, ? {
rootId: fr.rootId, path: fr.path,
state: fr.state, rootId: fr.rootId,
}; state: fr.state,
}
: fr;
}); });
} }
@ -258,11 +260,6 @@ const StackedRouter: Component<StackedRouterProps> = (oprops) => {
} }
}); });
/* createEffect(() => {
const length = stack.length;
console.debug("stack is changed", length, unwrap(stack));
}); */
createRenderEffect(() => { createRenderEffect(() => {
if (stack.length === 0) { if (stack.length === 0) {
pushFrame(window.location.pathname); pushFrame(window.location.pathname);
@ -271,8 +268,12 @@ const StackedRouter: Component<StackedRouterProps> = (oprops) => {
createRenderEffect(() => { createRenderEffect(() => {
makeEventListener(window, "popstate", (event) => { makeEventListener(window, "popstate", (event) => {
if (event.state && stack.length !== event.state.length) { if (!event.state) return;
if (stack.length === 0) {
mutStack(event.state); mutStack(event.state);
} else if (stack.length > event.state.length) {
popFrame(stack.length - event.state.length);
} }
}); });
}); });
@ -358,10 +359,7 @@ const StackedRouter: Component<StackedRouterProps> = (oprops) => {
reenterableAnimation.effect!.getComputedTiming(); reenterableAnimation.effect!.getComputedTiming();
const totalTime = (delay || 0) + Number(activeDuration); const totalTime = (delay || 0) + Number(activeDuration);
if ( if (Number(reenterableAnimation.currentTime) / totalTime > 0.1) {
Number(reenterableAnimation.currentTime) / totalTime >
0.1
) {
reenterableAnimation.addEventListener("finish", () => { reenterableAnimation.addEventListener("finish", () => {
onlyPopFrame(1); onlyPopFrame(1);
}); });

View file

@ -1,10 +1,7 @@
import { import {
children,
createSignal,
For, For,
Show, Show,
type JSX, type Component,
type ParentComponent,
} from "solid-js"; } from "solid-js";
import Scaffold from "../material/Scaffold.js"; import Scaffold from "../material/Scaffold.js";
import { import {
@ -44,7 +41,6 @@ import {
useDateFnLocale, useDateFnLocale,
} from "../platform/i18n.jsx"; } from "../platform/i18n.jsx";
import { type Template } from "@solid-primitives/i18n"; import { type Template } from "@solid-primitives/i18n";
import BottomSheet from "../material/BottomSheet.jsx";
import { useServiceWorker } from "../platform/host.js"; import { useServiceWorker } from "../platform/host.js";
import { useSessions } from "../masto/clients.js"; import { useSessions } from "../masto/clients.js";
import { useNavigator } from "../platform/StackedRouter.jsx"; import { useNavigator } from "../platform/StackedRouter.jsx";
@ -163,7 +159,7 @@ type Strings = {
["lang.auto"]: Template<{ detected: string }>; ["lang.auto"]: Template<{ detected: string }>;
} & Record<string, string | undefined>; } & Record<string, string | undefined>;
const Settings: ParentComponent = (props) => { const Settings: Component = () => {
const [t] = createTranslator( const [t] = createTranslator(
(code) => (code) =>
import(`./i18n/${code}.json`) as Promise<{ import(`./i18n/${code}.json`) as Promise<{
@ -173,7 +169,7 @@ const Settings: ParentComponent = (props) => {
); );
const {pop} = useNavigator(); const {pop} = useNavigator();
const settings$ = useStore($settings); const settings$ = useStore($settings);
const { needRefresh, offlineReady } = useServiceWorker(); const { needRefresh } = useServiceWorker();
const dateFnLocale = useDateFnLocale(); const dateFnLocale = useDateFnLocale();
const profiles = useSessions(); const profiles = useSessions();
@ -182,8 +178,6 @@ const Settings: ParentComponent = (props) => {
signOut((a) => a.site === acct.site && a.accessToken === acct.accessToken); signOut((a) => a.site === acct.site && a.accessToken === acct.accessToken);
}; };
const subpage = children(() => props.children);
css` css`
ul { ul {
padding: 0; padding: 0;
@ -209,10 +203,6 @@ const Settings: ParentComponent = (props) => {
</AppBar> </AppBar>
} }
> >
<BottomSheet open={!!subpage()} onClose={() => pop(1)}>
{subpage()}
</BottomSheet>
<List class="setting-list" use:solid-styled> <List class="setting-list" use:solid-styled>
<li> <li>
<ul> <ul>