refactor: unify dynamic page structure

This commit is contained in:
divocat
2025-10-14 21:49:09 +03:00
parent 33dfb8c3f0
commit 67ec5f3090
22 changed files with 430 additions and 404 deletions

View File

@@ -1,2 +1,7 @@
export * from './renderDashboard';
export * from './initDashboardController';
import { render } from './render';
import { initController } from './initController';
export const DashboardTab = {
render,
initController,
};

View File

@@ -5,14 +5,13 @@ import {
preserveScrollForPage,
} from '../../../helpers';
import { prettyBytes } from '../../../helpers/prettyBytes';
import { renderSections } from './renderSections';
import { renderWidget } from './renderWidget';
import {
ClashMethods,
CustomPodkopMethods,
PodkopShellMethods,
} from '../../methods';
import { socket, store, StoreType } from '../../services';
import { renderSections, renderWidget } from './partials';
// Fetchers
@@ -420,7 +419,7 @@ async function onStoreUpdate(
}
}
export async function initDashboardController(): Promise<void> {
export async function initController(): Promise<void> {
onMount('dashboard-status').then(() => {
// Remove old listener
store.unsubscribe(onStoreUpdate);

View File

@@ -0,0 +1,2 @@
export * from './renderSections';
export * from './renderWidget';

View File

@@ -1,5 +1,5 @@
import { Podkop } from '../../types';
import { getClashApiUrl } from '../../../helpers';
import { Podkop } from '../../../types';
import { getClashApiUrl } from '../../../../helpers';
interface IRenderSectionsProps {
loading: boolean;

View File

@@ -1,7 +1,6 @@
import { renderSections } from './renderSections';
import { renderWidget } from './renderWidget';
import { renderSections, renderWidget } from './partials';
export function renderDashboard() {
export function render() {
return E(
'div',
{

View File

@@ -1,13 +1,13 @@
import { updateDiagnosticsCheck } from '../updateDiagnosticsCheck';
import { insertIf } from '../../../../helpers';
import { DIAGNOSTICS_CHECKS_MAP } from './contstants';
import { PodkopShellMethods } from '../../../methods';
import { IDiagnosticsChecksItem } from '../../../services';
import { updateCheckStore } from './updateCheckStore';
export async function runDnsCheck() {
const { order, title, code } = DIAGNOSTICS_CHECKS_MAP.DNS;
updateDiagnosticsCheck({
updateCheckStore({
order,
code,
title,
@@ -19,7 +19,7 @@ export async function runDnsCheck() {
const dnsChecks = await PodkopShellMethods.checkDNSAvailable();
if (!dnsChecks.success) {
updateDiagnosticsCheck({
updateCheckStore({
order,
code,
title,
@@ -57,7 +57,7 @@ export async function runDnsCheck() {
return 'error';
}
updateDiagnosticsCheck({
updateCheckStore({
order,
code,
title,

View File

@@ -1,13 +1,13 @@
import { updateDiagnosticsCheck } from '../updateDiagnosticsCheck';
import { insertIf } from '../../../../helpers';
import { DIAGNOSTICS_CHECKS_MAP } from './contstants';
import { PodkopShellMethods, RemoteFakeIPMethods } from '../../../methods';
import { IDiagnosticsChecksItem } from '../../../services';
import { updateCheckStore } from './updateCheckStore';
export async function runFakeIPCheck() {
const { order, title, code } = DIAGNOSTICS_CHECKS_MAP.FAKEIP;
updateDiagnosticsCheck({
updateCheckStore({
order,
code,
title,
@@ -68,7 +68,7 @@ export async function runFakeIPCheck() {
const { state, description } = getMeta();
updateDiagnosticsCheck({
updateCheckStore({
order,
code,
title,

View File

@@ -1,11 +1,11 @@
import { updateDiagnosticsCheck } from '../updateDiagnosticsCheck';
import { DIAGNOSTICS_CHECKS_MAP } from './contstants';
import { RemoteFakeIPMethods, PodkopShellMethods } from '../../../methods';
import { updateCheckStore } from './updateCheckStore';
export async function runNftCheck() {
const { order, title, code } = DIAGNOSTICS_CHECKS_MAP.NFT;
updateDiagnosticsCheck({
updateCheckStore({
order,
code,
title,
@@ -20,7 +20,7 @@ export async function runNftCheck() {
const nftablesChecks = await PodkopShellMethods.checkNftRules();
if (!nftablesChecks.success) {
updateDiagnosticsCheck({
updateCheckStore({
order,
code,
title,
@@ -68,7 +68,7 @@ export async function runNftCheck() {
return 'error';
}
updateDiagnosticsCheck({
updateCheckStore({
order,
code,
title,

View File

@@ -1,11 +1,11 @@
import { updateDiagnosticsCheck } from '../updateDiagnosticsCheck';
import { DIAGNOSTICS_CHECKS_MAP } from './contstants';
import { PodkopShellMethods } from '../../../methods';
import { updateCheckStore } from './updateCheckStore';
export async function runSingBoxCheck() {
const { order, title, code } = DIAGNOSTICS_CHECKS_MAP.SINGBOX;
updateDiagnosticsCheck({
updateCheckStore({
order,
code,
title,
@@ -17,7 +17,7 @@ export async function runSingBoxCheck() {
const singBoxChecks = await PodkopShellMethods.checkSingBox();
if (!singBoxChecks.success) {
updateDiagnosticsCheck({
updateCheckStore({
order,
code,
title,
@@ -61,7 +61,7 @@ export async function runSingBoxCheck() {
return 'error';
}
updateDiagnosticsCheck({
updateCheckStore({
order,
code,
title,

View File

@@ -1,6 +1,6 @@
import { IDiagnosticsChecksStoreItem, store } from '../../services';
import { IDiagnosticsChecksStoreItem, store } from '../../../services';
export function updateDiagnosticsCheck(
export function updateCheckStore(
check: IDiagnosticsChecksStoreItem,
minified?: boolean,
) {

View File

@@ -1,2 +1,7 @@
export * from './renderDiagnostic';
export * from './initDiagnosticController';
import { render } from './renderDiagnostic';
import { initController } from './initController';
export const DiagnosticTab = {
render,
initController,
};

View File

@@ -1,14 +1,16 @@
import { onMount, preserveScrollForPage } from '../../../helpers';
import { renderCheckSection } from './renderCheckSection';
import { runDnsCheck } from './checks/runDnsCheck';
import { runSingBoxCheck } from './checks/runSingBoxCheck';
import { runNftCheck } from './checks/runNftCheck';
import { runFakeIPCheck } from './checks/runFakeIPCheck';
import { renderDiagnosticRunAction } from './renderDiagnosticRunAction';
import { renderAvailableActions } from './renderAvailableActions';
import { renderSystemInfo } from './renderSystemInfo';
import { loadingDiagnosticsChecksStore } from './diagnostic.store';
import { store, StoreType } from '../../services';
import {
renderAvailableActions,
renderCheckSection,
renderRunAction,
renderSystemInfo,
} from './partials';
function renderDiagnosticsChecks() {
console.log('renderDiagnosticsChecks');
@@ -32,7 +34,7 @@ function renderDiagnosticRunActionWidget() {
const { loading } = store.get().diagnosticsRunAction;
const container = document.getElementById('pdk_diagnostic-page-run-check');
const renderedAction = renderDiagnosticRunAction({
const renderedAction = renderRunAction({
loading,
click: () => runChecks(),
});
@@ -124,7 +126,7 @@ async function runChecks() {
}
}
export async function initDiagnosticController(): Promise<void> {
export async function initController(): Promise<void> {
onMount('diagnostic-status').then(() => {
console.log('diagnostic controller initialized.');
// Remove old listener

View File

@@ -0,0 +1,4 @@
export * from './renderAvailableActions';
export * from './renderCheckSection';
export * from './renderRunAction';
export * from './renderSystemInfo';

View File

@@ -7,8 +7,8 @@ import {
renderLoaderCircleIcon24,
renderTriangleAlertIcon24,
renderXIcon24,
} from '../../../icons';
import { IDiagnosticsChecksStoreItem } from '../../services';
} from '../../../../icons';
import { IDiagnosticsChecksStoreItem } from '../../../services';
type IRenderCheckSectionProps = IDiagnosticsChecksStoreItem;

View File

@@ -3,7 +3,7 @@ interface IRenderDiagnosticRunActionProps {
click: () => void;
}
export function renderDiagnosticRunAction({
export function renderRunAction({
loading,
click,
}: IRenderDiagnosticRunActionProps) {

View File

@@ -1,4 +1,4 @@
export function renderDiagnostic() {
export function render() {
return E('div', { id: 'diagnostic-status', class: 'pdk_diagnostic-page' }, [
E('div', { class: 'pdk_diagnostic-page__left-bar' }, [
E('div', { id: 'pdk_diagnostic-page-run-check' }),