-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zephyruso
authored and
Zephyruso
committed
Sep 1, 2023
1 parent
5250ccc
commit e9c6666
Showing
6 changed files
with
115 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { For } from 'solid-js' | ||
import { twMerge } from 'tailwind-merge' | ||
import { useProxies } from '~/signals/proxies' | ||
import { getClassNameByDelay } from '~/utils/proxies' | ||
|
||
const Delay = (p: { delay: number | undefined; selected: boolean }) => { | ||
const color = getClassNameByDelay(p.delay) | ||
const bgClassName = `bg-${color}` | ||
const isSelected = p.selected && `border-2 border-primary` | ||
|
||
return ( | ||
<div | ||
class={twMerge('m-1 h-4 w-4 rounded-full', bgClassName, isSelected)} | ||
></div> | ||
) | ||
} | ||
|
||
export default (props: { proxyNameList: string[]; now?: string }) => { | ||
const { proxyNodeMap } = useProxies() | ||
|
||
return ( | ||
<div class="flex w-full flex-wrap"> | ||
<For each={props.proxyNameList.map((name) => proxyNodeMap()[name]!)}> | ||
{(proxy) => { | ||
const delay = proxy?.delay | ||
const isSelected = props.now === proxy.name | ||
|
||
return <Delay delay={delay} selected={isSelected} /> | ||
}} | ||
</For> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import dayjs from 'dayjs' | ||
import relativeTime from 'dayjs/plugin/relativeTime' | ||
|
||
dayjs.extend(relativeTime) | ||
|
||
export function formatTimeFromNow(time: number | string) { | ||
return dayjs(time).fromNow() | ||
} | ||
|
||
export function getClassNameByDelay(delay: number | undefined) { | ||
let name = 'green-500' | ||
|
||
if (typeof delay !== 'number' || delay === 0) { | ||
name = 'base-100' | ||
} else if (delay > 500) { | ||
name = 'red-500' | ||
} else if (delay > 200) { | ||
name = 'yellow-500' | ||
} | ||
|
||
return name | ||
} |