import { createSignal, For, type JSX } from 'solid-js';
import XMark from 'heroicons/24/outline/x-mark.svg';
import BasicModal from '@/components/modal/BasicModal';
import UserNameDisplay from '@/components/UserDisplayName';
import useConfig, { type Config } from '@/core/useConfig';
import useModalState from '@/hooks/useModalState';
import usePubkey from '@/nostr/usePubkey';
import ensureNonNull from '@/utils/ensureNonNull';
type ConfigProps = {
onClose: () => void;
};
const BaseUrlRegex = (schemaRegex: string) =>
`^(?:${schemaRegex})://[-a-zA-Z0-9.]+(:\\d{1,5})?(?:/[-[\\]~!$&'()*+.,:;@&=%\\w]+|/)*(?:\\?[-[\\]~!$&'()*+.,/:;%@&=\\w?]+)?(?:#[-[\\]~!$&'()*+.,/:;%@\\w&=?#]+)?$`;
const HttpUrlRegex = BaseUrlRegex('https?');
const RelayUrlRegex = BaseUrlRegex('wss?');
const ProfileSection = () => {
const pubkey = usePubkey();
const { showProfile, showProfileEdit } = useModalState();
return (
プロフィール
);
};
const RelayConfig = () => {
const { config, addRelay, removeRelay } = useConfig();
const [relayUrlInput, setRelayUrlInput] = createSignal('');
const handleClickAddRelay: JSX.EventHandler = (ev) => {
ev.preventDefault();
if (relayUrlInput().length === 0) return;
addRelay(relayUrlInput());
setRelayUrlInput('');
};
return (
リレー
{(relayUrl: string) => {
return (
-
{relayUrl}
);
}}
);
};
const dateFormats: {
id: Config['dateFormat'];
name: string;
example: string;
}[] = [
{
id: 'relative',
name: '相対表記',
example: '7秒前',
},
{
id: 'absolute-short',
name: '絶対表記 (短形式)',
example: '昨日 23:55',
},
{
id: 'absolute-long',
name: '絶対表記 (長形式)',
example: '2020/11/8 21:02:53',
},
];
const DateFormatConfig = () => {
const { config, setConfig } = useConfig();
const updateDateFormat = (dateFormat: Config['dateFormat']) => {
setConfig((current) => ({ ...current, dateFormat }));
};
return (
時刻の表記
{({ id, name, example }) => (
{example}
)}
);
};
const ToggleButton = (props: {
value: boolean;
onClick: JSX.EventHandler;
}) => {
return (
);
};
const ReactionConfig = () => {
const { config, setConfig } = useConfig();
const toggleUseEmojiReaction = () => {
setConfig((current) => ({
...current,
useEmojiReaction: !(current.useEmojiReaction ?? false),
}));
};
const toggleShowEmojiReaction = () => {
setConfig((current) => ({
...current,
showEmojiReaction: !(current.showEmojiReaction ?? false),
}));
};
return (
リアクション
絵文字を選べるようにする
toggleUseEmojiReaction()}
/>
投稿にリアクションされた絵文字を表示する
toggleShowEmojiReaction()}
/>
);
};
const EmojiConfig = () => {
const { config, saveEmoji, removeEmoji } = useConfig();
const [shortcodeInput, setShortcodeInput] = createSignal('');
const [urlInput, setUrlInput] = createSignal('');
const handleClickSaveEmoji: JSX.EventHandler = (ev) => {
ev.preventDefault();
if (shortcodeInput().length === 0 || urlInput().length === 0) return;
saveEmoji({ shortcode: shortcodeInput(), url: urlInput() });
};
return (
カスタム絵文字
{({ shortcode, url }) => (
-
{shortcode}
)}
);
};
const MuteConfig = () => {
const { config, removeMutedPubkey, addMutedKeyword, removeMutedKeyword } = useConfig();
const [keywordInput, setKeywordInput] = createSignal('');
const handleClickAddKeyword: JSX.EventHandler = (ev) => {
ev.preventDefault();
if (keywordInput().length === 0) return;
addMutedKeyword(keywordInput());
setKeywordInput('');
};
return (
<>
ミュートしたユーザ
{(pubkey) => (
-
)}
ミュートした単語
{(keyword) => (
-
{keyword}
)}
>
);
};
const OtherConfig = () => {
const { config, setConfig } = useConfig();
const toggleKeepOpenPostForm = () => {
setConfig((current) => ({
...current,
keepOpenPostForm: !(current.keepOpenPostForm ?? false),
}));
};
const toggleShowImage = () => {
setConfig((current) => ({
...current,
showImage: !(current.showImage ?? true),
}));
};
const toggleHideCount = () => {
setConfig((current) => ({
...current,
hideCount: !(current.hideCount ?? false),
}));
};
return (
その他
投稿欄を開いたままにする
toggleKeepOpenPostForm()}
/>
画像をデフォルトで表示する
toggleShowImage()} />
いいねやリポスト、フォロワーなどの数を隠す
toggleHideCount()} />
{/*
*/}
);
};
const ConfigUI = (props: ConfigProps) => {
//