2023-09-02 00:15:19 +08:00
|
|
|
import { useI18n } from '@solid-primitives/i18n'
|
2023-09-02 17:42:13 +08:00
|
|
|
import { IconReload } from '@tabler/icons-solidjs'
|
2023-09-01 11:44:11 +08:00
|
|
|
import InfiniteScroll from 'solid-infinite-scroll'
|
2023-09-02 17:42:13 +08:00
|
|
|
import { For, Show, createMemo, createSignal, onMount } from 'solid-js'
|
2023-09-03 03:26:29 +08:00
|
|
|
import { Button } from '~/components'
|
2023-09-04 18:17:19 +08:00
|
|
|
import {
|
|
|
|
formatTimeFromNow,
|
|
|
|
handleAnimatedBtnClickWithCallback,
|
|
|
|
} from '~/helpers'
|
2023-09-03 03:26:29 +08:00
|
|
|
import { useRules } from '~/signals'
|
2023-08-28 22:13:48 +08:00
|
|
|
|
2023-08-29 14:44:49 +08:00
|
|
|
export default () => {
|
2023-09-02 00:15:19 +08:00
|
|
|
const [t] = useI18n()
|
2023-09-02 17:42:13 +08:00
|
|
|
const {
|
|
|
|
rules,
|
|
|
|
rulesProviders,
|
|
|
|
updateRules,
|
|
|
|
updateAllRuleProvider,
|
|
|
|
updateRuleProviderByName,
|
|
|
|
} = useRules()
|
2023-09-01 11:44:11 +08:00
|
|
|
const [maxRuleRender, setMaxRuleRender] = createSignal(100)
|
|
|
|
const renderRules = createMemo(() => rules().slice(0, maxRuleRender()))
|
2023-08-28 22:13:48 +08:00
|
|
|
|
2023-09-04 01:12:29 +08:00
|
|
|
onMount(updateRules)
|
2023-08-28 22:13:48 +08:00
|
|
|
|
2023-09-04 17:57:20 +08:00
|
|
|
const onUpdateProviderClick = (e: MouseEvent, name: string) => {
|
2023-09-04 18:17:19 +08:00
|
|
|
handleAnimatedBtnClickWithCallback(
|
|
|
|
e,
|
|
|
|
updateRuleProviderByName.bind(null, name),
|
|
|
|
)
|
2023-09-02 17:42:13 +08:00
|
|
|
}
|
2023-08-28 22:13:48 +08:00
|
|
|
|
2023-09-04 17:57:20 +08:00
|
|
|
const onUpdateAllProviderClick = (e: MouseEvent) => {
|
2023-09-04 18:17:19 +08:00
|
|
|
handleAnimatedBtnClickWithCallback(e, updateAllRuleProvider)
|
2023-09-02 17:42:13 +08:00
|
|
|
}
|
2023-08-28 22:13:48 +08:00
|
|
|
|
|
|
|
return (
|
2023-09-02 17:42:13 +08:00
|
|
|
<div class="flex w-full flex-row gap-4">
|
|
|
|
<div class="flex-1">
|
2023-09-02 00:15:19 +08:00
|
|
|
<h1 class="pb-4 text-lg font-semibold">{t('rules')}</h1>
|
2023-08-28 22:13:48 +08:00
|
|
|
|
2023-09-02 17:42:13 +08:00
|
|
|
<InfiniteScroll
|
|
|
|
each={renderRules()}
|
|
|
|
hasMore={renderRules().length < rules().length}
|
|
|
|
next={() => setMaxRuleRender(maxRuleRender() + 100)}
|
|
|
|
>
|
|
|
|
{(rule) => (
|
|
|
|
<div class="card card-bordered card-compact mb-2 bg-base-200 p-4">
|
2023-09-02 18:04:57 +08:00
|
|
|
<div class="break-all">
|
|
|
|
{rule.payload}
|
2023-09-04 20:00:43 +08:00
|
|
|
{typeof rule.size === 'number' &&
|
|
|
|
rule.size !== -1 &&
|
|
|
|
` (${rule.size})`}
|
2023-09-02 18:04:57 +08:00
|
|
|
</div>
|
2023-09-02 17:42:13 +08:00
|
|
|
<div class="text-xs text-slate-500">
|
|
|
|
{rule.type} :: {rule.proxy}
|
2023-08-28 22:13:48 +08:00
|
|
|
</div>
|
2023-09-02 17:42:13 +08:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</InfiniteScroll>
|
2023-08-28 22:13:48 +08:00
|
|
|
</div>
|
|
|
|
|
2023-09-02 17:42:13 +08:00
|
|
|
<Show when={rulesProviders().length > 0}>
|
|
|
|
<div class="flex-1">
|
|
|
|
<h1 class="flex h-11 items-center pb-4 text-lg font-semibold">
|
|
|
|
{t('ruleProviders')}
|
2023-09-03 02:31:06 +08:00
|
|
|
<Button
|
|
|
|
class="btn-circle btn-ghost btn-sm ml-2"
|
2023-09-02 17:42:13 +08:00
|
|
|
onClick={(e) => onUpdateAllProviderClick(e)}
|
|
|
|
>
|
|
|
|
<IconReload />
|
2023-09-03 02:31:06 +08:00
|
|
|
</Button>
|
2023-09-02 17:42:13 +08:00
|
|
|
</h1>
|
2023-08-28 22:13:48 +08:00
|
|
|
|
|
|
|
<For each={rulesProviders()}>
|
|
|
|
{(rulesProvider) => (
|
2023-09-02 17:42:13 +08:00
|
|
|
<div class="card card-bordered card-compact mb-2 bg-base-200 p-4">
|
|
|
|
<div class="flex h-6 items-center justify-between">
|
2023-09-02 18:04:57 +08:00
|
|
|
<span>
|
|
|
|
{rulesProvider.name} ({rulesProvider.ruleCount})
|
|
|
|
</span>
|
2023-09-02 17:42:13 +08:00
|
|
|
<div>
|
2023-09-03 02:31:06 +08:00
|
|
|
<Button
|
|
|
|
class="btn-circle btn-sm mr-2"
|
2023-09-02 17:42:13 +08:00
|
|
|
onClick={(e) =>
|
|
|
|
onUpdateProviderClick(e, rulesProvider.name)
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<IconReload />
|
2023-09-03 02:31:06 +08:00
|
|
|
</Button>
|
2023-09-02 17:42:13 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-08-31 10:50:43 +08:00
|
|
|
<div class="text-xs text-slate-500">
|
2023-09-02 18:04:57 +08:00
|
|
|
{rulesProvider.vehicleType} / {rulesProvider.behavior} /
|
2023-09-04 19:12:27 +08:00
|
|
|
{t('updated')} {formatTimeFromNow(rulesProvider.updatedAt)}
|
2023-08-28 22:13:48 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</For>
|
|
|
|
</div>
|
2023-09-02 17:42:13 +08:00
|
|
|
</Show>
|
2023-08-28 22:13:48 +08:00
|
|
|
</div>
|
|
|
|
)
|
2023-08-24 04:20:53 +08:00
|
|
|
}
|