Skip to content

Commit

Permalink
feat: infinite scroll for rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Zephyruso authored and Zephyruso committed Sep 1, 2023
1 parent bdb2055 commit a05c548
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/pages/Proxies.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -115,7 +115,7 @@ export default () => {
</div>
</div>

<div>
<Show when={proxyProviders().length > 0}>
<h1 class="pb-4 text-lg font-semibold">Proxy Providers</h1>

<div class="grid grid-cols-1 gap-2 sm:grid-cols-2">
Expand Down Expand Up @@ -174,7 +174,7 @@ export default () => {
}}
</For>
</div>
</div>
</Show>
</div>
)
}
13 changes: 10 additions & 3 deletions src/pages/Rules.tsx
Original file line number Diff line number Diff line change
@@ -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<Rule[]>([])
const [rulesProviders, setRulesProviders] = createSignal<RuleProvider[]>([])
const renderRules = createMemo(() => rules().slice(0, maxRuleRender()))

onMount(async () => {
const { rules } = await request
Expand All @@ -27,7 +30,11 @@ export default () => {
<h1 class="pb-4 text-lg font-semibold">Rules</h1>

<div class="grid grid-cols-1 gap-2 sm:grid-cols-1">
<For each={rules()}>
<InfiniteScroll
each={renderRules()}
hasMore={renderRules().length < rules().length}
next={() => setMaxRuleRender(maxRuleRender() + 100)}
>
{(rule) => (
<div class="card card-bordered card-compact bg-base-200 p-4">
<div class="break-all">{rule.payload}</div>
Expand All @@ -36,7 +43,7 @@ export default () => {
</div>
</div>
)}
</For>
</InfiniteScroll>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/signals/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a05c548

Please sign in to comment.