SHA256
UI: свайпы вкладок и навигация тредов
This commit is contained in:
+62
-2
@@ -1,6 +1,10 @@
|
||||
import { parseShineRouteParts } from './services/shine-routes.js';
|
||||
|
||||
const ROOT_PAGES = ['messages-list', 'channels-list', 'network-view', 'notifications-view', 'profile-view'];
|
||||
const SWIPEABLE_ROOT_PAGES = ['messages-list', 'channels-list', 'notifications-view', 'profile-view'];
|
||||
const lastVisitedRouteByRoot = new Map();
|
||||
let previousTrackedPath = '';
|
||||
let currentTrackedPath = String(window.location.pathname || '').trim() || '/';
|
||||
const PRETTY_PATHS = new Map([
|
||||
['start-view', 'start'],
|
||||
['entry-settings-view', 'entry-settings'],
|
||||
@@ -68,8 +72,8 @@ export const PRE_AUTH_PAGES = [
|
||||
'key-storage-view',
|
||||
];
|
||||
|
||||
export function getRoute() {
|
||||
const currentPath = String(window.location.pathname || '').trim();
|
||||
export function parseRouteFromPath(pathname = '') {
|
||||
const currentPath = String(pathname || '').trim();
|
||||
const raw = currentPath
|
||||
.replace(/^\/+/, '')
|
||||
.replace(/^index\.html$/i, '')
|
||||
@@ -344,15 +348,29 @@ export function getRoute() {
|
||||
return { pageId, params: {} };
|
||||
}
|
||||
|
||||
export function getRoute() {
|
||||
return parseRouteFromPath(window.location.pathname || '');
|
||||
}
|
||||
|
||||
export function navigate(path) {
|
||||
const cleanPath = toPrettyPath(path);
|
||||
const nextPath = cleanPath ? `/${cleanPath}` : '/';
|
||||
if (window.location.pathname !== nextPath) {
|
||||
previousTrackedPath = currentTrackedPath;
|
||||
currentTrackedPath = nextPath;
|
||||
}
|
||||
if (window.location.pathname !== nextPath) {
|
||||
window.history.pushState({}, '', nextPath);
|
||||
}
|
||||
window.dispatchEvent(new PopStateEvent('popstate'));
|
||||
}
|
||||
|
||||
function normalizeCurrentPath() {
|
||||
return String(window.location.pathname || '')
|
||||
.replace(/^\/+/, '')
|
||||
.replace(/\/+$/, '');
|
||||
}
|
||||
|
||||
export function toPrettyPath(path) {
|
||||
const raw = String(path || '').replace(/^\/+/, '').replace(/\/+$/, '');
|
||||
if (!raw) return '';
|
||||
@@ -397,3 +415,45 @@ export function resolveToolbarActive(pageId) {
|
||||
if (pageId === 'user') return 'messages-list';
|
||||
return 'profile-view';
|
||||
}
|
||||
|
||||
export function rememberToolbarRoute(pageId, explicitPath = '') {
|
||||
const rootPageId = resolveToolbarActive(pageId);
|
||||
if (!ROOT_PAGES.includes(rootPageId)) return;
|
||||
const cleanPath = String(explicitPath || normalizeCurrentPath()).trim();
|
||||
lastVisitedRouteByRoot.set(rootPageId, cleanPath || toPrettyPath(rootPageId) || rootPageId);
|
||||
}
|
||||
|
||||
export function getToolbarNavigationTarget(pageId) {
|
||||
const rootPageId = resolveToolbarActive(pageId);
|
||||
return lastVisitedRouteByRoot.get(rootPageId) || toPrettyPath(rootPageId) || rootPageId;
|
||||
}
|
||||
|
||||
export function resetRememberedToolbarRoutes() {
|
||||
lastVisitedRouteByRoot.clear();
|
||||
previousTrackedPath = '';
|
||||
currentTrackedPath = String(window.location.pathname || '').trim() || '/';
|
||||
}
|
||||
|
||||
export function getSwipeNavigationTarget(currentPageId, direction) {
|
||||
const rootPageId = resolveToolbarActive(currentPageId);
|
||||
const index = SWIPEABLE_ROOT_PAGES.indexOf(rootPageId);
|
||||
if (index === -1) return '';
|
||||
|
||||
const step = direction === 'left' ? 1 : direction === 'right' ? -1 : 0;
|
||||
if (!step) return '';
|
||||
|
||||
const nextIndex = index + step;
|
||||
if (nextIndex < 0 || nextIndex >= SWIPEABLE_ROOT_PAGES.length) return '';
|
||||
return getToolbarNavigationTarget(SWIPEABLE_ROOT_PAGES[nextIndex]);
|
||||
}
|
||||
|
||||
export function syncTrackedRouteHistory(pathname = '') {
|
||||
const nextPath = String(pathname || '').trim() || '/';
|
||||
if (nextPath === currentTrackedPath) return;
|
||||
previousTrackedPath = currentTrackedPath;
|
||||
currentTrackedPath = nextPath;
|
||||
}
|
||||
|
||||
export function getPreviousTrackedPath() {
|
||||
return previousTrackedPath;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user