Skip to content

Commit

Permalink
Add manually connect to relay feature
Browse files Browse the repository at this point in the history
  • Loading branch information
heguro committed Mar 19, 2023
1 parent edd306d commit a189eec
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/components/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export const Main = () => {
useState<ContactList | null>(null);
const [relaysInputText, setRelaysInputText] = useState('');
const [showKind10002, setShowKind10002] = useState(false);
const [relayAddInput, setRelayAddInput] = useState('');

const { setLang, lang } = useContext(PrefsContext);
const { setLogin, login } = useContext(LoginContext);
Expand Down Expand Up @@ -742,6 +743,35 @@ export const Main = () => {
{t('setting.showKind10002.label')}
</label>
</div>
<div>
<form
onSubmit={evt => {
evt.preventDefault();
const url = relayUrlNormalize(relayAddInput);
if (/^((ws|http)s?:\/\/)?[\w.-]+(\/|$)/.test(url)) {
if (connections[url]?.status !== 'connected') {
addConnection(relayAddInput, true);
}
setRelayAddInput('');
}
}}>
<label for="relay-add-input">
{t('setting.addRelayManually.label')}:{' '}
<input
type="text"
id="relay-add-input"
placeholder="wss://relay.damus.io"
value={relayAddInput}
onInput={({ target }) => {
if (target instanceof HTMLInputElement) {
setRelayAddInput(target.value);
}
}}
/>
<button type="submit">接続</button>
</label>
</form>
</div>
<div>
<label for="lang-select">
{t('setting.lang.label')}:{' '}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
"relays.relay.w": "w",
"relays.reset": "Reset",
"relays.send": "Send",
"setting.addRelayManually.button": "Connect",
"setting.addRelayManually.label": "Manually add relay to connect",
"setting.label": "Settings",
"setting.lang.label": "Language",
"setting.publishMode.all": "As many relays as possible",
Expand Down
2 changes: 2 additions & 0 deletions src/lib/i18n/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
"relays.relay.w": "",
"relays.reset": "リセット",
"relays.send": "送信",
"setting.addRelayManually.button": "接続",
"setting.addRelayManually.label": "リレー手動接続",
"setting.label": "設定",
"setting.lang.label": "言語(Language)",
"setting.publishMode.all": "できるだけ多くのリレー",
Expand Down

0 comments on commit a189eec

Please sign in to comment.