このコミットが含まれているのは:
+23
-18
@@ -2,12 +2,9 @@ import { apiGet, apiPatch } from '@/lib/api'
|
||||
|
||||
import type { FetchPostsOrder, FetchTagsOrder } from '@/types'
|
||||
|
||||
// DB-backed user settings. These are worth sharing across browsers for one user.
|
||||
// DB-backed user settings. These are the cross-device preferences worth syncing.
|
||||
export type UserSettings = {
|
||||
theme: 'system' | 'light' | 'dark'
|
||||
autoFetchTitle: 'auto' | 'manual' | 'off'
|
||||
autoFetchThumbnail: 'auto' | 'manual' | 'off'
|
||||
wikiEditorMode: 'split' | 'write' | 'preview' }
|
||||
theme: 'system' | 'light' | 'dark' }
|
||||
|
||||
export type TheatreLayoutMode = 'threeColumns' | 'tagsBottom' | 'commentsBottom'
|
||||
export type TheatreTagFlow = 'vertical' | 'horizontal'
|
||||
@@ -24,10 +21,14 @@ type ClientListSettings = {
|
||||
limit?: ClientListLimit
|
||||
order?: string }
|
||||
|
||||
// Browser-local settings. These depend on device or screen context.
|
||||
type ClientKeyboardSettings = {
|
||||
shortcutsEnabled?: boolean }
|
||||
|
||||
// Browser-local settings. These stay device-specific and are not synced to DB.
|
||||
export type ClientSettings = {
|
||||
panes?: Record<string, ClientPaneSettings>
|
||||
lists?: Partial<Record<ClientListKey, ClientListSettings>>
|
||||
keyboard?: ClientKeyboardSettings
|
||||
theatre?: {
|
||||
layoutMode?: TheatreLayoutMode
|
||||
tagFlow?: TheatreTagFlow
|
||||
@@ -41,14 +42,9 @@ export type ClientSettings = {
|
||||
|
||||
export const CLIENT_SETTINGS_STORAGE_KEY = 'btrc_hub.client_settings'
|
||||
export const DEFAULT_USER_SETTINGS: UserSettings = {
|
||||
theme: 'system',
|
||||
autoFetchTitle: 'manual',
|
||||
autoFetchThumbnail: 'manual',
|
||||
wikiEditorMode: 'split' }
|
||||
theme: 'system' }
|
||||
|
||||
export const THEME_OPTIONS = ['system', 'light', 'dark'] as const
|
||||
export const AUTO_FETCH_OPTIONS = ['auto', 'manual', 'off'] as const
|
||||
export const WIKI_EDITOR_MODE_OPTIONS = ['split', 'write', 'preview'] as const
|
||||
export const LIST_LIMIT_OPTIONS = [20, 50, 100] as const
|
||||
export const POST_LIST_ORDER_OPTIONS = [
|
||||
'title:asc',
|
||||
@@ -89,12 +85,7 @@ export const fetchUserSettings = async (): Promise<UserSettings> =>
|
||||
|
||||
|
||||
export const updateUserSettings = async (
|
||||
settings: Partial<{
|
||||
theme: UserSettings['theme']
|
||||
auto_fetch_title: UserSettings['autoFetchTitle']
|
||||
auto_fetch_thumbnail: UserSettings['autoFetchThumbnail']
|
||||
wiki_editor_mode: UserSettings['wikiEditorMode']
|
||||
}>,
|
||||
settings: Partial<{ theme: UserSettings['theme'] }>,
|
||||
): Promise<UserSettings> => await apiPatch<UserSettings> ('/users/settings', settings)
|
||||
|
||||
|
||||
@@ -171,6 +162,20 @@ export const setClientListSettings = (
|
||||
}
|
||||
|
||||
|
||||
export const getClientKeyboardShortcutsEnabled = (): boolean =>
|
||||
loadClientSettings ().keyboard?.shortcutsEnabled ?? true
|
||||
|
||||
|
||||
export const setClientKeyboardShortcutsEnabled = (
|
||||
enabled: boolean,
|
||||
): void => {
|
||||
updateClientSettings (settings => ({
|
||||
...settings,
|
||||
keyboard: { ...(settings.keyboard ?? { }), shortcutsEnabled: enabled },
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
const legacyTheatreLayoutMode = (): TheatreLayoutMode | null => {
|
||||
const value = localStorage.getItem (LEGACY_THEATRE_LAYOUT_STORAGE_KEY)
|
||||
return (
|
||||
|
||||
新しい課題から参照
ユーザをブロックする