Use better behavior on disconnected radio and allow deeplinking into settings. Closes #66.

This commit is contained in:
Jack Kingsman
2026-03-16 17:46:12 -07:00
parent ffb5fa51c1
commit b68bfc41d6
14 changed files with 359 additions and 56 deletions
+31
View File
@@ -1,6 +1,7 @@
import type { Channel, Contact, Conversation } from '../types';
import { findPublicChannel, PUBLIC_CHANNEL_NAME } from './publicChannel';
import { getContactDisplayName } from './pubkey';
import type { SettingsSection } from '../components/settings/settingsConstants';
interface ParsedHashConversation {
type: 'channel' | 'contact' | 'raw' | 'map' | 'visualizer' | 'search';
@@ -12,6 +13,15 @@ interface ParsedHashConversation {
mapFocusKey?: string;
}
const SETTINGS_SECTIONS: SettingsSection[] = [
'radio',
'local',
'fanout',
'database',
'statistics',
'about',
];
// Parse URL hash to get conversation
// (e.g., #channel/ABCDEF0123456789ABCDEF0123456789 or #contact/<64-char-pubkey>).
export function parseHashConversation(): ParsedHashConversation | null {
@@ -70,6 +80,20 @@ export function parseHashConversation(): ParsedHashConversation | null {
};
}
export function parseHashSettingsSection(): SettingsSection | null {
const hash = window.location.hash.slice(1);
if (!hash.startsWith('settings/')) {
return null;
}
const section = decodeURIComponent(hash.slice('settings/'.length)) as SettingsSection;
return SETTINGS_SECTIONS.includes(section) ? section : null;
}
export function getSettingsHash(section: SettingsSection): string {
return `#settings/${encodeURIComponent(section)}`;
}
export function resolveChannelFromHashToken(token: string, channels: Channel[]): Channel | null {
const normalizedToken = token.trim();
if (!normalizedToken) return null;
@@ -141,3 +165,10 @@ export function updateUrlHash(conv: Conversation | null): void {
window.history.replaceState(null, '', newHash || window.location.pathname);
}
}
export function updateSettingsHash(section: SettingsSection): void {
const newHash = getSettingsHash(section);
if (newHash !== window.location.hash) {
window.history.replaceState(null, '', newHash);
}
}