diff --git a/src/backend/controllers/session.ts b/src/backend/controllers/session.ts index 0f56d59..8e7bc6c 100644 --- a/src/backend/controllers/session.ts +++ b/src/backend/controllers/session.ts @@ -29,7 +29,7 @@ export class SessionController { if (setting.visibility != null) s.visibility = setting.visibility; if (setting.localOnly != null) s.localOnly = setting.localOnly; 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; await updateUser(user.username, user.host, s); } diff --git a/src/frontend/components/SettingPage.tsx b/src/frontend/components/SettingPage.tsx index 0099592..fefc370 100644 --- a/src/frontend/components/SettingPage.tsx +++ b/src/frontend/components/SettingPage.tsx @@ -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 { 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 { useSelector } from '../store'; import { languageName } from '../langs'; +import insertTextAtCursor from 'insert-text-at-cursor'; const variables = [ 'notesCount', @@ -56,6 +57,8 @@ export const SettingPage: React.VFC = () => { const currentTheme = useSelector(state => state.screen.theme); const currentLang = useSelector(state => state.screen.language); + const templateTextarea = useRef(null); + const availableVisibilities: Visibility[] = [ 'public', 'home', @@ -111,10 +114,14 @@ export const SettingPage: React.VFC = () => { screenY: e.clientY, items: variables.map(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(() => { dispatch(showModal({ @@ -149,14 +156,14 @@ export const SettingPage: React.VFC = () => { }).then(() => { dispatch(showModal({ type: 'dialog', - message: t('_logout.success'), + message: t('_sendTest.success'), icon: 'info', })); }).catch((e) => { console.error(e); dispatch(showModal({ type: 'dialog', - message: t('_logout.failure'), + message: t('_sendTest.failure'), icon: 'error', })); }); @@ -328,7 +335,7 @@ export const SettingPage: React.VFC = () => { -