From 3ea70724376259c717b65e1c59b7a10a9c1817b9 Mon Sep 17 00:00:00 2001 From: thislight Date: Mon, 14 Oct 2024 20:05:08 +0800 Subject: [PATCH] TootBottomSheet: set document title --- src/timelines/TootBottomSheet.tsx | 9 ++++++++- src/utils.tsx | 15 ++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/timelines/TootBottomSheet.tsx b/src/timelines/TootBottomSheet.tsx index 0081c97..caa0054 100644 --- a/src/timelines/TootBottomSheet.tsx +++ b/src/timelines/TootBottomSheet.tsx @@ -24,6 +24,7 @@ import { css } from "solid-styled"; import { vibrate } from "../platform/hardware"; import { createTimeSource, TimeSourceProvider } from "../platform/timesrc"; import TootComposer from "./TootComposer"; +import { useDocumentTitle } from "../utils"; let cachedEntry: [string, mastodon.v1.Status] | undefined; @@ -106,8 +107,14 @@ const TootBottomSheet: Component = (props) => { } }); + useDocumentTitle(() => { + const t = toot()?.reblog ?? toot() + const name = t?.account.displayName ?? "Someone" + return `${name}'s toot` + }) + const tootDisplayName = () => { - const t = toot(); + const t = toot()?.reblog ?? toot(); if (t) { return resolveCustomEmoji(t.account.displayName, t.account.emojis); } diff --git a/src/utils.tsx b/src/utils.tsx index 9ca5052..167df79 100644 --- a/src/utils.tsx +++ b/src/utils.tsx @@ -1,18 +1,23 @@ -import { createRenderEffect, createSignal, onCleanup } from "solid-js"; +import { + createRenderEffect, + onCleanup, + type Accessor, +} from "solid-js"; -export function useDocumentTitle(newTitle?: string) { +export function useDocumentTitle(newTitle?: string | Accessor) { const capturedTitle = document.title; - const [title, setTitle] = createSignal(newTitle ?? capturedTitle); createRenderEffect(() => { - document.title = title(); + if (newTitle) + document.title = typeof newTitle === "string" ? newTitle : newTitle(); }); onCleanup(() => { document.title = capturedTitle; }); - return setTitle; + return (x: ((x: string) => string) | string) => + (document.title = typeof x === "string" ? x : x(document.title)); } export function mergeClass(c1: string | undefined, c2: string | undefined) {