import React, { useCallback, useEffect, useReducer } from 'react'; import { alertModes } from '../../common/types/alert-mode'; import { IUser } from '../../common/types/user'; import { Visibility } from '../../common/types/visibility'; import { useGetSessionQuery } from '../services/session'; import { defaultTemplate } from '../../common/default-template'; import { Card } from './Card'; import { Theme } from '../misc/theme'; import { API_ENDPOINT, LOCALSTORAGE_KEY_LANG, LOCALSTORAGE_KEY_TOKEN } from '../const'; import { useDispatch } from 'react-redux'; import { changeLang, changeTheme, showModal } from '../store/slices/screen'; import { useSelector } from '../store'; import { languageName } from '../langs'; type SettingDraftType = Partial>; type DraftReducer = React.Reducer>; export const SettingPage: React.VFC = () => { const session = useGetSessionQuery(undefined); const dispatch = useDispatch(); const data = session.data; const [draft, dispatchDraft] = useReducer((state, action) => { return { ...state, ...action }; }, { alertMode: data?.alertMode ?? 'note', visibility: data?.visibility ?? 'public', localOnly: data?.localOnly ?? false, remoteFollowersOnly: data?.remoteFollowersOnly ?? false, template: data?.template ?? null, }); const themes: Array<{ theme: Theme, name: string }> = [ { theme: 'light', name: 'ライトテーマ' }, { theme: 'dark', name: 'ダークテーマ' }, { theme: 'system', name: 'システム設定に準じる' }, ]; const currentTheme = useSelector(state => state.screen.theme); const currentLang = useSelector(state => state.screen.lang); const availableVisibilities: Visibility[] = [ 'public', 'home', 'followers' ]; const updateSetting = useCallback((obj: SettingDraftType) => { dispatchDraft(obj); return fetch(`${API_ENDPOINT}session`, { method: 'PUT', headers: { 'Authorization': `Bearer ${localStorage[LOCALSTORAGE_KEY_TOKEN]}`, 'Content-Type': 'application/json', }, body: JSON.stringify(obj), }); }, []); const updateSettingWithDialog = useCallback((obj: SettingDraftType) => { updateSetting(obj) .then(() => dispatch(showModal({ type: 'dialog', icon: 'info', message: '保存しました。' }))) .catch(e => { alert(e.message); }); }, [updateSetting]); useEffect(() => { if (data) { dispatchDraft({ alertMode: data.alertMode, visibility: data.visibility, localOnly: data.localOnly, remoteFollowersOnly: data.remoteFollowersOnly, template: data.template, }); } }, [data]); const onClickSendAlert = useCallback(() => { dispatch(showModal({ type: 'dialog', title: 'アラートをテスト送信しますか?', message: '現在の設定でアラートを送信します。設定が保存済みであるかどうか、実行前に必ずご確認ください。', icon: 'question', buttons: 'yesNo', onSelect(i) { if (i === 0) { fetch(`${API_ENDPOINT}session/alert`, { method: 'POST', headers: { 'Authorization': `Bearer ${localStorage[LOCALSTORAGE_KEY_TOKEN]}`, }, }).then(() => { dispatch(showModal({ type: 'dialog', message: '送信しました。', icon: 'info', })); }).catch((e) => { console.error(e); dispatch(showModal({ type: 'dialog', message: '送信に失敗しました。', icon: 'error', })); }); } }, })); }, [dispatch]); const onClickLogout = useCallback(() => { dispatch(showModal({ type: 'dialog', message: 'WIP', })); }, [dispatch]); const onClickDeleteAccount = useCallback(() => { dispatch(showModal({ type: 'dialog', message: 'WIP', })); }, [dispatch]); return session.isLoading || !data ? (
) : (

アラート送信方法

{ alertModes.map((mode) => ( )) } {draft.alertMode === 'notification' && (
「Misskey に通知」オプションは古いMisskeyでは動作しません。
)}
{ draft.alertMode === 'note' && (
{ availableVisibilities.map((visibility) => ( )) }
)}

表示設定

テーマ

{ themes.map(({ theme, name }) => ( )) }

言語設定

テンプレート

アラートの自動投稿をカスタマイズできます。