diff --git a/src/components/modal/AddColumn.tsx b/src/components/modal/AddColumn.tsx index edfc4a2..5cd2832 100644 --- a/src/components/modal/AddColumn.tsx +++ b/src/components/modal/AddColumn.tsx @@ -1,10 +1,11 @@ -import { Component, For } from 'solid-js'; +import { Component, For, Switch, Match, createSignal, type JSX } from 'solid-js'; import Bell from 'heroicons/24/outline/bell.svg'; import GlobeAlt from 'heroicons/24/outline/globe-alt.svg'; import Heart from 'heroicons/24/outline/heart.svg'; import Home from 'heroicons/24/outline/home.svg'; import MagnifyingGlass from 'heroicons/24/outline/magnifying-glass.svg'; +import Server from 'heroicons/24/outline/server.svg'; import User from 'heroicons/24/outline/user.svg'; // import BookmarkIcon from 'heroicons/24/outline/bookmark.svg'; // import ChatBubbleLeftRight from 'heroicons/24/outline/chat-bubble-left-right.svg'; @@ -16,6 +17,7 @@ import { createNotificationColumn, createPostsColumn, createReactionsColumn, + createRelaysColumn, createSearchColumn, } from '@/core/column'; import useConfig from '@/core/useConfig'; @@ -23,17 +25,78 @@ import { useRequestCommand } from '@/hooks/useCommandBus'; import { useTranslation } from '@/i18n/useTranslation'; import usePubkey from '@/nostr/usePubkey'; import ensureNonNull from '@/utils/ensureNonNull'; +import { isWebSocketUrl } from '@/utils/url'; type AddColumnProps = { onClose: () => void; }; +type AddRelayColumnProps = { + addRelaysColumn: (relayUrls: string[]) => void; +}; + +const AddRelaysColumn: Component = (props) => { + const i18n = useTranslation(); + const { config } = useConfig(); + + const [relayUrl, setRelayUrl] = createSignal(''); + + const handleSubmit: JSX.EventHandler = (ev) => { + ev.preventDefault(); + + const url = relayUrl(); + if (!isWebSocketUrl(url)) { + window.alert('Invalid url'); + return; + } + + props.addRelaysColumn([url]); + }; + + return ( +
+
+ setRelayUrl(ev.currentTarget.value)} + /> + +
+
+ + {(url) => ( + + )} + +
+
+ ); +}; + const AddColumn: Component = (props) => { const i18n = useTranslation(); const pubkey = usePubkey(); const { saveColumn } = useConfig(); const request = useRequestCommand(); + const [detailComponent, setDetailComponent] = createSignal(undefined); + const finish = () => { props.onClose(); request({ command: 'moveToLastColumn' }).catch((err) => console.error(err)); @@ -58,6 +121,11 @@ const AddColumn: Component = (props) => { finish(); }; + const addRelaysColumn = (relayUrls: string[]) => { + saveColumn(createRelaysColumn({ relayUrls })); + finish(); + }; + const addSearchColumn = () => { saveColumn(createSearchColumn({ query: '' })); finish(); @@ -81,32 +149,37 @@ const AddColumn: Component = (props) => { { name: () => i18n.t('column.home'), icon: () => , - onClick: addFollowingColumn, + onSelect: addFollowingColumn, }, { name: () => i18n.t('column.notification'), icon: () => , - onClick: addNotificationColumn, + onSelect: addNotificationColumn, + }, + { + name: () => i18n.t('column.relay'), + icon: () => , + onSelect: () => setDetailComponent('AddRelaysColumn'), }, { name: () => i18n.t('column.japanese'), icon: () => , - onClick: addJapanRelaysColumn, + onSelect: addJapanRelaysColumn, }, { name: () => i18n.t('column.search'), icon: () => , - onClick: addSearchColumn, + onSelect: addSearchColumn, }, { name: () => i18n.t('column.myPosts'), icon: () => , - onClick: addMyPostsColumn, + onSelect: addMyPostsColumn, }, { name: () => i18n.t('column.myReactions'), icon: () => , - onClick: addMyReactionsColumn, + onSelect: addMyReactionsColumn, }, // TODO channel // TODO bookmark @@ -114,19 +187,27 @@ const AddColumn: Component = (props) => { return ( -
- - {(menuItem) => ( - - )} - -
+ + + {(menuItem) => ( + + )} + + + } + > + + + +
); }; diff --git a/src/locales/ja.ts b/src/locales/ja.ts index 7f00c55..f674acd 100644 --- a/src/locales/ja.ts +++ b/src/locales/ja.ts @@ -37,6 +37,9 @@ export default { back: '戻る', loadLatest: '最新の投稿を読み込む', loadOld: '古い投稿を読み込む', + addRelayColumn: { + add: '追加', + }, config: { columnWidth: 'カラム幅', widest: '特大',