From a05c54854a3ffb1b9d079e14f9d48c0d2e79d2f3 Mon Sep 17 00:00:00 2001 From: Zephyruso <127948745+Zephyruso@users.noreply.github.com> Date: Fri, 1 Sep 2023 11:44:11 +0800 Subject: [PATCH] feat: infinite scroll for rules --- package.json | 1 + pnpm-lock.yaml | 12 ++++++++++++ src/pages/Proxies.tsx | 6 +++--- src/pages/Rules.tsx | 13 ++++++++++--- src/signals/proxies.ts | 2 +- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 55a95d6..625cdc6 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "prettier-plugin-organize-imports": "^3.2.3", "prettier-plugin-tailwindcss": "^0.5.4", "solid-apexcharts": "^0.3.2", + "solid-infinite-scroll": "^1.0.1", "solid-js": "^1.7.11", "sort-package-json": "^2.5.1", "tailwind-merge": "^1.14.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 134d851..6653f58 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -92,6 +92,9 @@ dependencies: solid-apexcharts: specifier: ^0.3.2 version: 0.3.2(apexcharts@3.42.0)(solid-js@1.7.11) + solid-infinite-scroll: + specifier: ^1.0.1 + version: 1.0.1 solid-js: specifier: ^1.7.11 version: 1.7.11 @@ -4040,6 +4043,15 @@ packages: solid-js: 1.7.11 dev: false + /solid-infinite-scroll@1.0.1: + resolution: + { + integrity: sha512-yIDyr61316jyHSxuQqidMUTcauKDQyPIzIAKawTrTadqxij2wOcM3ei6/MR6WPBCcR0ZMJ8E0aQInFSnL9w2Hg==, + } + dependencies: + solid-js: 1.7.11 + dev: false + /solid-js@1.7.11: resolution: { diff --git a/src/pages/Proxies.tsx b/src/pages/Proxies.tsx index d018a90..10a5275 100644 --- a/src/pages/Proxies.tsx +++ b/src/pages/Proxies.tsx @@ -1,5 +1,5 @@ import { IconBrandSpeedtest, IconReload } from '@tabler/icons-solidjs' -import { For, createSignal, onMount } from 'solid-js' +import { For, Show, createSignal, onMount } from 'solid-js' import Collapse from '~/components/Collpase' import ProxyNodeCard from '~/components/ProxyNodeCard' import { useProxies } from '~/signals/proxies' @@ -115,7 +115,7 @@ export default () => { -
+ 0}>

Proxy Providers

@@ -174,7 +174,7 @@ export default () => { }}
-
+ ) } diff --git a/src/pages/Rules.tsx b/src/pages/Rules.tsx index 19133a7..f0aac85 100644 --- a/src/pages/Rules.tsx +++ b/src/pages/Rules.tsx @@ -1,11 +1,14 @@ -import { For, createSignal, onMount } from 'solid-js' +import InfiniteScroll from 'solid-infinite-scroll' +import { For, createMemo, createSignal, onMount } from 'solid-js' import { useRequest } from '~/signals' import type { Rule, RuleProvider } from '~/types' export default () => { const request = useRequest() + const [maxRuleRender, setMaxRuleRender] = createSignal(100) const [rules, setRules] = createSignal([]) const [rulesProviders, setRulesProviders] = createSignal([]) + const renderRules = createMemo(() => rules().slice(0, maxRuleRender())) onMount(async () => { const { rules } = await request @@ -27,7 +30,11 @@ export default () => {

Rules

- + setMaxRuleRender(maxRuleRender() + 100)} + > {(rule) => (
{rule.payload}
@@ -36,7 +43,7 @@ export default () => {
)} - + diff --git a/src/signals/proxies.ts b/src/signals/proxies.ts index fbf6e6e..23e21de 100644 --- a/src/signals/proxies.ts +++ b/src/signals/proxies.ts @@ -32,7 +32,7 @@ export function useProxies() { Object.values(proxies).forEach((proxy) => { setProxyNodeMap({ ...proxyNodeMap(), [proxy.name]: proxy }) - delay[proxy.name] = proxy.history[proxy.history.length - 1]?.delay + delay[proxy.name] = proxy.history.at(-1)?.delay ?? 0 }) setDelayMap(delay)