SHA256
Скрыть тестовые версии связей по умолчанию
This commit is contained in:
@@ -20,6 +20,8 @@ export const pageMeta = {
|
||||
};
|
||||
|
||||
const normalizeLogin = (value) => String(value || '').trim();
|
||||
const PERSONAL_LAYOUT_PREFIX = 'shine-network-explorer-layout-v1:';
|
||||
const MAX_PERSONAL_LAYOUT_POINTS = 1200;
|
||||
const escapeHtml = (text) => String(text || '').replaceAll('&', '&').replaceAll('<', '<')
|
||||
.replaceAll('>', '>').replaceAll('"', '"').replaceAll("'", ''');
|
||||
function createDebounced(fn, ms = 2000) {
|
||||
@@ -34,8 +36,42 @@ function hash01(value) {
|
||||
return (h >>> 0) / 4294967296;
|
||||
}
|
||||
|
||||
// Своя карта хранится локально и только для владельца аккаунта. Координаты всегда
|
||||
// относительны к нему самому (его точка — 0,0), поэтому при возвращении к себе
|
||||
// расстановка не зависит от того, чью сеть пользователь открывал перед этим.
|
||||
function personalLayoutKey(login) {
|
||||
return `${PERSONAL_LAYOUT_PREFIX}${keyOf(login)}`;
|
||||
}
|
||||
function readPersonalLayout(login) {
|
||||
try {
|
||||
const saved = JSON.parse(localStorage.getItem(personalLayoutKey(login)) || '{}');
|
||||
if (!saved || typeof saved !== 'object' || !saved.points || typeof saved.points !== 'object') return new Map();
|
||||
const points = new Map();
|
||||
Object.entries(saved.points).slice(0, MAX_PERSONAL_LAYOUT_POINTS).forEach(([id, point]) => {
|
||||
if (Array.isArray(point) && Number.isFinite(point[0]) && Number.isFinite(point[1])) {
|
||||
points.set(keyOf(id), { x: point[0], y: point[1] });
|
||||
}
|
||||
});
|
||||
return points;
|
||||
} catch {
|
||||
return new Map();
|
||||
}
|
||||
}
|
||||
function writePersonalLayout(login, points) {
|
||||
try {
|
||||
const stored = {};
|
||||
[...points.entries()].slice(0, MAX_PERSONAL_LAYOUT_POINTS).forEach(([id, point]) => {
|
||||
if (Number.isFinite(point?.x) && Number.isFinite(point?.y)) stored[keyOf(id)] = [Math.round(point.x), Math.round(point.y)];
|
||||
});
|
||||
localStorage.setItem(personalLayoutKey(login), JSON.stringify({ points: stored, updatedAt: Date.now() }));
|
||||
} catch {
|
||||
// В приватном режиме или при переполнении сохранённая до конца сессии карта всё равно работает.
|
||||
}
|
||||
}
|
||||
|
||||
// V3/V4 сохраняют исследование при переключении версий внутри вкладки.
|
||||
// Новый вход через нижнюю кнопку «Связи» очищает карту и IndexedDB-графы.
|
||||
// Новый вход через нижнюю кнопку очищает только исследованные данные; личная
|
||||
// расстановка на стартовой карте остаётся у пользователя.
|
||||
let retained = null;
|
||||
let resetBarrier = Promise.resolve();
|
||||
export function resetExplorerOnTabEntry() {
|
||||
@@ -68,7 +104,7 @@ export function renderExplorer({ navigate, route, chrome } = {}, { canvas = fals
|
||||
|
||||
const scope = explorerCacheScope(authService, state.session.login);
|
||||
if (!retained || retained.scope !== scope) retained = {
|
||||
scope, graph: createExplorerGraph(), positions: new Map(), center: '',
|
||||
scope, graph: createExplorerGraph(), positions: readPersonalLayout(state.session.login), center: '',
|
||||
depth: 3, x2: true, close: false, shining: false,
|
||||
};
|
||||
const session = retained;
|
||||
@@ -81,6 +117,15 @@ export function renderExplorer({ navigate, route, chrome } = {}, { canvas = fals
|
||||
let searchClose = null;
|
||||
let cacheWasCleared = false;
|
||||
|
||||
function persistPersonalLayout() {
|
||||
if (keyOf(centerLogin) !== keyOf(state.session.login)) return;
|
||||
const self = keyOf(state.session.login);
|
||||
if (!self || !session.positions.has(self)) return;
|
||||
// На личной карте центр всегда фиксирован в начале координат. Сохраняем
|
||||
// только в этом состоянии, чтобы переход к чужому человеку не сдвинул карту.
|
||||
writePersonalLayout(state.session.login, session.positions);
|
||||
}
|
||||
|
||||
function profileRoute(login) {
|
||||
if (keyOf(login) === keyOf(state.session.login)) return 'profile-view';
|
||||
return makeProfileRoute(login);
|
||||
@@ -118,8 +163,9 @@ export function renderExplorer({ navigate, route, chrome } = {}, { canvas = fals
|
||||
const center = keyOf(centerLogin);
|
||||
if (!session.positions.has(center)) session.positions.set(center, { x: 0, y: 0 });
|
||||
const pending = nodes.filter((node) => !session.positions.has(node.id)).sort((a, b) => a.distance - b.distance);
|
||||
const spacing = 84;
|
||||
const minNodeGap = 66;
|
||||
// Большие аватары стоят на 30% дальше друг от друга, чем в прежней карте.
|
||||
const spacing = 109.2;
|
||||
const minNodeGap = 85.8;
|
||||
for (const node of pending) {
|
||||
const connected = (adjacency.get(node.id) || []).filter((id) => session.positions.has(id));
|
||||
const nearest = connected.sort((a, b) => (byId.get(a)?.distance ?? 99) - (byId.get(b)?.distance ?? 99))[0];
|
||||
@@ -168,6 +214,7 @@ export function renderExplorer({ navigate, route, chrome } = {}, { canvas = fals
|
||||
const x = Number(row?.x); const y = Number(row?.y);
|
||||
if (keyOf(row?.id) && Number.isFinite(x) && Number.isFinite(y)) session.positions.set(keyOf(row.id), { x, y });
|
||||
});
|
||||
persistPersonalLayout();
|
||||
}
|
||||
function nodeMenu(node, long = false, point = null) {
|
||||
const canvasPoint = canvas ? engine?.nodeScreenPoint?.(node) : null;
|
||||
@@ -444,6 +491,7 @@ export function renderExplorer({ navigate, route, chrome } = {}, { canvas = fals
|
||||
screen.cleanup = () => {
|
||||
if (disposed) return;
|
||||
disposed = true;
|
||||
persistPersonalLayout();
|
||||
++loadSeq;
|
||||
if (drawTimer) window.clearTimeout(drawTimer);
|
||||
window.clearInterval(refreshTimer);
|
||||
|
||||
Reference in New Issue
Block a user