SHA256
Доработать исследователь сети и кошелёк
This commit is contained in:
@@ -7,7 +7,7 @@ import { CONNECTIONS_GRAPH_CHANGED } from '../../services/connections-graph-cach
|
||||
import { createForceGraph } from '../network-legacy/force-graph.js';
|
||||
import { createExplorerCanvasGraph } from '../network-canvas-v4/graph-renderer.js';
|
||||
import { openNodeMenu } from '../network-legacy/node-menu.js';
|
||||
import { createExplorerGraph, keyOf, EXPLORER_DEFAULT_DEPTH, EXPLORER_MAX_DEPTH } from './graph-model.js';
|
||||
import { createExplorerGraph, keyOf } from './graph-model.js';
|
||||
import { getExplorerGraph, readExplorerCachedGraphs, clearExplorerGraphCache, explorerCacheScope, explorerGraphSavedAt } from './graph-cache.js';
|
||||
|
||||
export const pageMeta = {
|
||||
@@ -69,7 +69,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: '',
|
||||
depth: EXPLORER_DEFAULT_DEPTH, x2: false, close: false, shining: false, compact: false,
|
||||
depth: 3, x2: true, close: false, shining: false,
|
||||
};
|
||||
const session = retained;
|
||||
let centerLogin = normalizeLogin(route?.params?.login || session.center || state.session.login);
|
||||
@@ -118,8 +118,8 @@ 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 = session.compact ? 62 : 84;
|
||||
const minNodeGap = session.compact ? 48 : 66;
|
||||
const spacing = 84;
|
||||
const minNodeGap = 66;
|
||||
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];
|
||||
@@ -223,14 +223,13 @@ export function renderExplorer({ navigate, route, chrome } = {}, { canvas = fals
|
||||
if (disposed || seq !== loadSeq) return;
|
||||
if (!ok) { updateStatus(t('screens.network_explorer.error')); return; }
|
||||
draw();
|
||||
if (!session.x2) { updateStatus(); return; }
|
||||
|
||||
const friends = [...(session.graph.getFriends(next) || [])];
|
||||
let index = 0;
|
||||
let finished = 0;
|
||||
let failed = 0;
|
||||
const workers = Array.from({ length: Math.min(4, friends.length) }, async () => {
|
||||
while (index < friends.length && !disposed && seq === loadSeq && session.x2) {
|
||||
while (index < friends.length && !disposed && seq === loadSeq) {
|
||||
const friend = friends[index++];
|
||||
if (!await fetchGraph(friend, seq)) failed += 1;
|
||||
finished += 1;
|
||||
@@ -243,56 +242,43 @@ export function renderExplorer({ navigate, route, chrome } = {}, { canvas = fals
|
||||
updateStatus(failed ? t('screens.network_explorer.partial', { value1: failed }) : '');
|
||||
}
|
||||
|
||||
function chip(label, fn, selected = false) {
|
||||
const element = document.createElement('button');
|
||||
element.type = 'button'; element.className = `fg-filter-chip${selected ? ' is-active' : ''}`;
|
||||
element.textContent = label;
|
||||
element.setAttribute('aria-pressed', selected ? 'true' : 'false');
|
||||
element.addEventListener('click', fn);
|
||||
toolbar.append(element);
|
||||
return element;
|
||||
// Верхняя панель содержит только активные фильтры; меню читает то же состояние.
|
||||
function syncFilters() {
|
||||
toolbar.replaceChildren();
|
||||
for (const [key, label] of [
|
||||
['close', 'screens.network_explorer.only_close'],
|
||||
['shining', 'screens.network_explorer.only_shining'],
|
||||
]) {
|
||||
if (!session[key]) continue;
|
||||
const button = document.createElement('button');
|
||||
button.type = 'button';
|
||||
button.className = 'fg-filter-chip is-active';
|
||||
button.textContent = t(label);
|
||||
button.setAttribute('aria-pressed', 'true');
|
||||
button.addEventListener('click', () => toggleFilter(key));
|
||||
toolbar.append(button);
|
||||
}
|
||||
toolbar.hidden = !session.close && !session.shining;
|
||||
}
|
||||
function actionChip(label, fn) {
|
||||
const element = document.createElement('button');
|
||||
element.type = 'button'; element.className = 'fg-filter-chip';
|
||||
element.textContent = label;
|
||||
element.addEventListener('click', fn);
|
||||
toolbar.append(element);
|
||||
return element;
|
||||
function toggleFilter(key) {
|
||||
session[key] = !session[key];
|
||||
syncFilters();
|
||||
draw();
|
||||
}
|
||||
const closeChip = chip(t('screens.network_view.text_002'), () => {
|
||||
session.close = !session.close;
|
||||
closeChip.classList.toggle('is-active', session.close);
|
||||
closeChip.setAttribute('aria-pressed', String(session.close));
|
||||
function toggleHistory() {
|
||||
session.depth = session.depth === 3 ? 0 : 3;
|
||||
draw();
|
||||
}, session.close);
|
||||
const shineChip = chip(t('screens.network_view.text_003'), () => {
|
||||
session.shining = !session.shining;
|
||||
shineChip.classList.toggle('is-active', session.shining);
|
||||
shineChip.setAttribute('aria-pressed', String(session.shining));
|
||||
draw();
|
||||
}, session.shining);
|
||||
const x2Chip = chip('X2', () => {
|
||||
session.x2 = !session.x2;
|
||||
x2Chip.classList.toggle('is-active', session.x2);
|
||||
x2Chip.setAttribute('aria-pressed', String(session.x2));
|
||||
void load(centerLogin);
|
||||
}, session.x2);
|
||||
const depthChip = chip('', () => {
|
||||
session.depth = (session.depth + 1) % (EXPLORER_MAX_DEPTH + 1);
|
||||
syncDepth(); draw();
|
||||
});
|
||||
actionChip(t('screens.network_explorer.compact'), () => {
|
||||
session.compact = true;
|
||||
session.positions.clear();
|
||||
draw();
|
||||
});
|
||||
function syncDepth() {
|
||||
depthChip.textContent = t('screens.network_explorer.depth', { value1: session.depth });
|
||||
depthChip.title = t('screens.network_explorer.depth_hint', { value1: session.depth + (session.x2 ? 2 : 1) });
|
||||
depthChip.setAttribute('aria-label', depthChip.title);
|
||||
}
|
||||
syncDepth();
|
||||
function showMe() {
|
||||
const login = normalizeLogin(state.session.login);
|
||||
if (!login || disposed) return;
|
||||
// load() сдвигает координаты при смене центра; для уже выбранного себя
|
||||
// тоже возвращаем узел в начало координат, если он был перемещён вручную.
|
||||
if (keyOf(login) === keyOf(centerLogin)) shiftToCenter(login);
|
||||
void load(login, true);
|
||||
engine?.centerCamera?.();
|
||||
}
|
||||
syncFilters();
|
||||
|
||||
async function resetCache() {
|
||||
++loadSeq;
|
||||
@@ -435,8 +421,14 @@ export function renderExplorer({ navigate, route, chrome } = {}, { canvas = fals
|
||||
icon: 'moreVertical', title: t('screens.network_explorer.menu'),
|
||||
ariaLabel: t('screens.network_explorer.menu'),
|
||||
menu: {
|
||||
items: [
|
||||
items: () => [
|
||||
{ iconHtml: iconHtml('search'), label: t('screens.network_explorer.search'), action: openSearchModal },
|
||||
{ iconHtml: iconHtml('focus'), label: t('screens.network_explorer.show_me'), disabled: !normalizeLogin(state.session.login), action: showMe },
|
||||
{ divider: true },
|
||||
{ label: t('screens.network_explorer.only_close'), checked: session.close, action: () => toggleFilter('close') },
|
||||
{ label: t('screens.network_explorer.only_shining'), checked: session.shining, action: () => toggleFilter('shining') },
|
||||
{ label: t('screens.network_explorer.show_history'), checked: session.depth === 3, action: toggleHistory },
|
||||
{ divider: true },
|
||||
{ iconHtml: iconHtml('trash'), label: t('screens.network_explorer.clear_cache'), action: () => void resetCache() },
|
||||
],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user