mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-08-02 15:03:01 +02:00
Use better behavior on disconnected radio and allow deeplinking into settings. Closes #66.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user