バグ修正など

This commit is contained in:
xeltica 2021-10-03 03:12:53 +09:00
parent e2e6185aa4
commit 6903530e51
3 changed files with 17 additions and 9 deletions

View File

@ -29,7 +29,7 @@ export class SessionController {
if (setting.visibility != null) s.visibility = setting.visibility; if (setting.visibility != null) s.visibility = setting.visibility;
if (setting.localOnly != null) s.localOnly = setting.localOnly; if (setting.localOnly != null) s.localOnly = setting.localOnly;
if (setting.remoteFollowersOnly != null) s.remoteFollowersOnly = setting.remoteFollowersOnly; if (setting.remoteFollowersOnly != null) s.remoteFollowersOnly = setting.remoteFollowersOnly;
if (setting.template != null) s.template = setting.template; if (setting.template !== undefined) s.template = setting.template;
if (Object.keys(s).length === 0) return; if (Object.keys(s).length === 0) return;
await updateUser(user.username, user.host, s); await updateUser(user.username, user.host, s);
} }

View File

@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useReducer } from 'react'; import React, { useCallback, useEffect, useReducer, useRef } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';
@ -12,6 +12,7 @@ import { API_ENDPOINT, LOCALSTORAGE_KEY_TOKEN } from '../const';
import { changeLang, changeTheme, showModal } from '../store/slices/screen'; import { changeLang, changeTheme, showModal } from '../store/slices/screen';
import { useSelector } from '../store'; import { useSelector } from '../store';
import { languageName } from '../langs'; import { languageName } from '../langs';
import insertTextAtCursor from 'insert-text-at-cursor';
const variables = [ const variables = [
'notesCount', 'notesCount',
@ -56,6 +57,8 @@ export const SettingPage: React.VFC = () => {
const currentTheme = useSelector(state => state.screen.theme); const currentTheme = useSelector(state => state.screen.theme);
const currentLang = useSelector(state => state.screen.language); const currentLang = useSelector(state => state.screen.language);
const templateTextarea = useRef<HTMLTextAreaElement>(null);
const availableVisibilities: Visibility[] = [ const availableVisibilities: Visibility[] = [
'public', 'public',
'home', 'home',
@ -111,10 +114,14 @@ export const SettingPage: React.VFC = () => {
screenY: e.clientY, screenY: e.clientY,
items: variables.map(key => ({ items: variables.map(key => ({
name: t('_template._variables.' + key), name: t('_template._variables.' + key),
onClick: () => { console.log(key); }, onClick: () => {
if (templateTextarea.current) {
insertTextAtCursor(templateTextarea.current, `{${key}}`);
}
},
})), })),
})); }));
}, [dispatch, t, variables]); }, [dispatch, t, variables, templateTextarea.current]);
const onClickInsertVariablesHelp = useCallback(() => { const onClickInsertVariablesHelp = useCallback(() => {
dispatch(showModal({ dispatch(showModal({
@ -149,14 +156,14 @@ export const SettingPage: React.VFC = () => {
}).then(() => { }).then(() => {
dispatch(showModal({ dispatch(showModal({
type: 'dialog', type: 'dialog',
message: t('_logout.success'), message: t('_sendTest.success'),
icon: 'info', icon: 'info',
})); }));
}).catch((e) => { }).catch((e) => {
console.error(e); console.error(e);
dispatch(showModal({ dispatch(showModal({
type: 'dialog', type: 'dialog',
message: t('_logout.failure'), message: t('_sendTest.failure'),
icon: 'error', icon: 'error',
})); }));
}); });
@ -328,7 +335,7 @@ export const SettingPage: React.VFC = () => {
<i className="bi bi-question-circle" /> <i className="bi bi-question-circle" />
</button> </button>
</div> </div>
<textarea className="input-field" value={draft.template ?? defaultTemplate} placeholder={defaultTemplate} style={{height: 228}} onChange={(e) => { <textarea ref={templateTextarea} className="input-field" value={draft.template ?? defaultTemplate} placeholder={defaultTemplate} style={{height: 228}} onChange={(e) => {
dispatchDraft({ template: e.target.value }); dispatchDraft({ template: e.target.value });
}} /> }} />
<small className="text-dimmed">{t('_template.description2')}</small> <small className="text-dimmed">{t('_template.description2')}</small>
@ -340,8 +347,8 @@ export const SettingPage: React.VFC = () => {
</div> </div>
</Card> </Card>
<Card bodyClassName="vstack"> <Card bodyClassName="vstack">
<button className="btn block" onClick={onClickSendAlert}>{t('sendAlert')}</button> <button className="btn block" onClick={onClickSendAlert} disabled={draft.alertMode === 'nothing'}>{t('sendAlert')}</button>
<p className="text-dimmed">{t('sendAlertDescription')}</p> <p className="text-dimmed">{t(draft.alertMode === 'nothing' ? 'sendAlertDisabled' : 'sendAlertDescription')}</p>
</Card> </Card>
<Card bodyClassName="vstack"> <Card bodyClassName="vstack">
<button className="btn block" onClick={onClickLogout}>{t('logout')}</button> <button className="btn block" onClick={onClickLogout}>{t('logout')}</button>

View File

@ -12,6 +12,7 @@
"template": "テンプレート", "template": "テンプレート",
"sendAlert": "アラートをテスト送信する", "sendAlert": "アラートをテスト送信する",
"sendAlertDescription": "現在の設定を用いて、アラート送信をテストします。", "sendAlertDescription": "現在の設定を用いて、アラート送信をテストします。",
"sendAlertDisabled": "アラート送信方法が「通知しない」のため、送信をテストすることはできません。",
"logout": "ログアウトする", "logout": "ログアウトする",
"logoutDescription": "ログアウトしても、アラートは送信されます。", "logoutDescription": "ログアウトしても、アラートは送信されます。",
"deleteAccount": "アカウント連携を解除する", "deleteAccount": "アカウント連携を解除する",