Simplify page title logic per review
This commit is contained in:
@@ -170,6 +170,15 @@ src/
|
|||||||
- Do not define svelte event handlers inline, instead name them and put them in the script section of templates
|
- Do not define svelte event handlers inline, instead name them and put them in the script section of templates
|
||||||
- Avoid using `as`, except where necessary. Instead, annotate function parameters, and ensure upstream values are typed correctly.
|
- Avoid using `as`, except where necessary. Instead, annotate function parameters, and ensure upstream values are typed correctly.
|
||||||
|
|
||||||
|
**Human-First Simplicity (Jon Staab Style):**
|
||||||
|
|
||||||
|
- Prefer direct, readable code over layered abstractions.
|
||||||
|
- Do not add indirection (extra helpers, wrappers, stores, or derived state) unless it removes real repeated complexity.
|
||||||
|
- Reuse existing Welshman and Flotilla primitives before introducing new utilities or dependencies.
|
||||||
|
- Favor linear control flow and explicit naming over clever patterns.
|
||||||
|
- Remove defensive checks that do not apply in this runtime model.
|
||||||
|
- When two approaches work, pick the one that feels more human and easier to maintain.
|
||||||
|
|
||||||
## Common Tasks
|
## Common Tasks
|
||||||
|
|
||||||
### Adding a New Component
|
### Adding a New Component
|
||||||
|
|||||||
+6
-18
@@ -1,13 +1,7 @@
|
|||||||
import {append, identity, uniq} from "@welshman/lib"
|
import {append, identity, uniq} from "@welshman/lib"
|
||||||
import {displayPubkey, getTagValue, type Filter, type TrustedEvent} from "@welshman/util"
|
import {repository} from "@welshman/app"
|
||||||
import {
|
import {displayPubkey, getTagValue} from "@welshman/util"
|
||||||
PLATFORM_NAME,
|
import {PLATFORM_NAME, decodeRelay, getRoom, makeRoomId, splitChatId} from "@app/core/state"
|
||||||
decodeRelay,
|
|
||||||
getEventsForUrl,
|
|
||||||
getRoom,
|
|
||||||
makeRoomId,
|
|
||||||
splitChatId,
|
|
||||||
} from "@app/core/state"
|
|
||||||
|
|
||||||
const FALLBACK_APP_NAME = "Flotilla"
|
const FALLBACK_APP_NAME = "Flotilla"
|
||||||
|
|
||||||
@@ -69,10 +63,8 @@ const getRoomTitle = (params: RouteParams) => {
|
|||||||
return getRoom(makeRoomId(url, h))?.name || "Room"
|
return getRoom(makeRoomId(url, h))?.name || "Room"
|
||||||
}
|
}
|
||||||
|
|
||||||
const getEventForTitle = (routeId: string, params: RouteParams): TrustedEvent | undefined => {
|
const getEventForTitle = (routeId: string, params: RouteParams) => {
|
||||||
const relay = params.relay
|
if (!eventRoutes.has(routeId)) {
|
||||||
|
|
||||||
if (!relay || !eventRoutes.has(routeId)) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,11 +74,7 @@ const getEventForTitle = (routeId: string, params: RouteParams): TrustedEvent |
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = decodeRelay(relay)
|
return repository.getEvent(eventId)
|
||||||
const filters: Filter[] = [{ids: [eventId], limit: 1}]
|
|
||||||
const events = Array.from(getEventsForUrl(url, filters))
|
|
||||||
|
|
||||||
return events[0]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const getChatTitle = (chatId: string | undefined, pubkey: string | undefined) => {
|
const getChatTitle = (chatId: string | undefined, pubkey: string | undefined) => {
|
||||||
|
|||||||
@@ -48,10 +48,6 @@
|
|||||||
|
|
||||||
const {children} = $props()
|
const {children} = $props()
|
||||||
|
|
||||||
const pageTitle = $derived.by(() => {
|
|
||||||
return getPageTitle({page: $page, pubkey: $pubkey})
|
|
||||||
})
|
|
||||||
|
|
||||||
const policies = [authPolicy, blockPolicy, trustPolicy, mostlyRestrictedPolicy]
|
const policies = [authPolicy, blockPolicy, trustPolicy, mostlyRestrictedPolicy]
|
||||||
|
|
||||||
// Add stuff to window for convenience
|
// Add stuff to window for convenience
|
||||||
@@ -207,9 +203,7 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (typeof document !== "undefined") {
|
document.title = getPageTitle({page: $page, pubkey: $pubkey})
|
||||||
document.title = pageTitle
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user