mirror of
https://github.com/aljazceru/rabbit.git
synced 2025-12-17 14:04:21 +01:00
feat: config for dateFormat
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import useConfig from '@/nostr/useConfig';
|
import useConfig, { type Config } from '@/nostr/useConfig';
|
||||||
import { createSignal, For, type JSX } from 'solid-js';
|
import { createSignal, For, type JSX } from 'solid-js';
|
||||||
|
|
||||||
type ConfigProps = {
|
type ConfigProps = {
|
||||||
@@ -48,7 +48,61 @@ const RelayConfig = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const Config = (props: ConfigProps) => {
|
const dateFormats: { id: Config['dateFormat']; name: string; example: string }[] = [
|
||||||
|
{
|
||||||
|
id: 'relative',
|
||||||
|
name: '相対',
|
||||||
|
example: '〜秒前',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'absolute-short',
|
||||||
|
name: '絶対 (短形式)',
|
||||||
|
example: '昨日 12:34',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'absolute-long',
|
||||||
|
name: '絶対 (長形式)',
|
||||||
|
example: '2023',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const DateFormatConfig = () => {
|
||||||
|
const { config, setConfig } = useConfig();
|
||||||
|
|
||||||
|
const updateDateFormat = (dateFormat: Config['dateFormat']) => {
|
||||||
|
setConfig((current) => ({ ...current, dateFormat }));
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h3 class="font-bold">時刻の表記</h3>
|
||||||
|
<div class="flex justify-evenly gap-2">
|
||||||
|
<For each={dateFormats}>
|
||||||
|
{({ id, name, example }) => (
|
||||||
|
<div class="flex flex-1 flex-col items-center">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="w-full rounded border border-rose-300 p-2 font-bold"
|
||||||
|
classList={{
|
||||||
|
'bg-rose-300': config().dateFormat === id,
|
||||||
|
'text-white': config().dateFormat === id,
|
||||||
|
'bg-white': config().dateFormat !== id,
|
||||||
|
'text-rose-300': config().dateFormat !== id,
|
||||||
|
}}
|
||||||
|
onClick={() => updateDateFormat(id)}
|
||||||
|
>
|
||||||
|
{name}
|
||||||
|
</button>
|
||||||
|
{example}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</For>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const ConfigUI = (props: ConfigProps) => {
|
||||||
let containerRef: HTMLDivElement | undefined;
|
let containerRef: HTMLDivElement | undefined;
|
||||||
|
|
||||||
const handleClickContainer: JSX.EventHandler<HTMLDivElement, MouseEvent> = (ev) => {
|
const handleClickContainer: JSX.EventHandler<HTMLDivElement, MouseEvent> = (ev) => {
|
||||||
@@ -72,9 +126,10 @@ const Config = (props: ConfigProps) => {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<RelayConfig />
|
<RelayConfig />
|
||||||
|
<DateFormatConfig />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Config;
|
export default ConfigUI;
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ const TextNoteDisplay: Component<TextNoteDisplayProps> = (props) => {
|
|||||||
</div>
|
</div>
|
||||||
<Show when={showReplyEvent()} keyed>
|
<Show when={showReplyEvent()} keyed>
|
||||||
{(id) => (
|
{(id) => (
|
||||||
<div class="relative border p-1">
|
<div class="border p-1">
|
||||||
<TextNoteDisplayById eventId={id} actions={false} embedding={false} />
|
<TextNoteDisplayById eventId={id} actions={false} embedding={false} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -233,7 +233,7 @@ const TextNoteDisplay: Component<TextNoteDisplayProps> = (props) => {
|
|||||||
<div class="text-sm text-zinc-400">{reactions().length}</div>
|
<div class="text-sm text-zinc-400">{reactions().length}</div>
|
||||||
</Show>
|
</Show>
|
||||||
</div>
|
</div>
|
||||||
<div class="relative">
|
<div>
|
||||||
<button
|
<button
|
||||||
class="h-4 w-4 text-zinc-400"
|
class="h-4 w-4 text-zinc-400"
|
||||||
onClick={() => setShowMenu((current) => !current)}
|
onClick={() => setShowMenu((current) => !current)}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
createSignalWithStorage,
|
createSignalWithStorage,
|
||||||
} from '@/hooks/createSignalWithStorage';
|
} from '@/hooks/createSignalWithStorage';
|
||||||
|
|
||||||
type Config = {
|
export type Config = {
|
||||||
relayUrls: string[];
|
relayUrls: string[];
|
||||||
dateFormat: 'relative' | 'absolute-long' | 'absolute-short';
|
dateFormat: 'relative' | 'absolute-long' | 'absolute-short';
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user