forked from Archives/Athou_commafeed
move other settings to localSettings too
This commit is contained in:
@@ -3,8 +3,7 @@ import { entriesSlice } from "app/entries/slice"
|
||||
import { redirectSlice } from "app/redirect/slice"
|
||||
import { serverSlice } from "app/server/slice"
|
||||
import { treeSlice } from "app/tree/slice"
|
||||
import type { ViewMode } from "app/types"
|
||||
import { userSlice } from "app/user/slice"
|
||||
import { initialLocalSettings, userSlice } from "app/user/slice"
|
||||
import { type TypedUseSelectorHook, useDispatch, useSelector } from "react-redux"
|
||||
|
||||
export const reducers = {
|
||||
@@ -19,15 +18,13 @@ export const store = configureStore({
|
||||
reducer: reducers,
|
||||
preloadedState: {
|
||||
user: {
|
||||
localSettings: {
|
||||
viewMode: localStorage.getItem("view-mode") as ViewMode,
|
||||
},
|
||||
localSettings: JSON.parse(localStorage.getItem("commafeed-local-settings") ?? JSON.stringify(initialLocalSettings)),
|
||||
},
|
||||
},
|
||||
})
|
||||
store.subscribe(() => {
|
||||
const state = store.getState()
|
||||
localStorage.setItem("view-mode", state.user.localSettings.viewMode)
|
||||
const localSettings = store.getState().user.localSettings
|
||||
localStorage.setItem("commafeed-local-settings", JSON.stringify(localSettings))
|
||||
})
|
||||
|
||||
export type RootState = ReturnType<typeof store.getState>
|
||||
|
||||
@@ -254,6 +254,12 @@ export interface Settings {
|
||||
sharingSettings: SharingSettings
|
||||
}
|
||||
|
||||
export interface LocalSettings {
|
||||
viewMode: ViewMode
|
||||
sidebarWidth: number
|
||||
announcementHash: string
|
||||
}
|
||||
|
||||
export interface StarRequest {
|
||||
id: string
|
||||
feedId: number
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { t } from "@lingui/macro"
|
||||
import { showNotification } from "@mantine/notifications"
|
||||
import { type PayloadAction, createSlice, isAnyOf } from "@reduxjs/toolkit"
|
||||
import type { Settings, UserModel, ViewMode } from "app/types"
|
||||
import type { LocalSettings, Settings, UserModel, ViewMode } from "app/types"
|
||||
import {
|
||||
changeCustomContextMenu,
|
||||
changeEntriesToKeepOnTopWhenScrolling,
|
||||
@@ -26,17 +26,19 @@ import {
|
||||
|
||||
interface UserState {
|
||||
settings?: Settings
|
||||
localSettings: {
|
||||
viewMode: ViewMode
|
||||
}
|
||||
localSettings: LocalSettings
|
||||
profile?: UserModel
|
||||
tags?: string[]
|
||||
}
|
||||
|
||||
export const initialLocalSettings: LocalSettings = {
|
||||
viewMode: "detailed",
|
||||
sidebarWidth: 360,
|
||||
announcementHash: "no-hash",
|
||||
}
|
||||
|
||||
const initialState: UserState = {
|
||||
localSettings: {
|
||||
viewMode: "detailed",
|
||||
},
|
||||
localSettings: initialLocalSettings,
|
||||
}
|
||||
|
||||
export const userSlice = createSlice({
|
||||
@@ -46,6 +48,12 @@ export const userSlice = createSlice({
|
||||
setViewMode: (state, action: PayloadAction<ViewMode>) => {
|
||||
state.localSettings.viewMode = action.payload
|
||||
},
|
||||
setSidebarWidth: (state, action: PayloadAction<number>) => {
|
||||
state.localSettings.sidebarWidth = action.payload
|
||||
},
|
||||
setAnnouncementHash: (state, action: PayloadAction<string>) => {
|
||||
state.localSettings.announcementHash = action.payload
|
||||
},
|
||||
},
|
||||
extraReducers: builder => {
|
||||
builder.addCase(reloadSettings.fulfilled, (state, action) => {
|
||||
@@ -148,4 +156,4 @@ export const userSlice = createSlice({
|
||||
},
|
||||
})
|
||||
|
||||
export const { setViewMode } = userSlice.actions
|
||||
export const { setViewMode, setSidebarWidth, setAnnouncementHash } = userSlice.actions
|
||||
|
||||
Reference in New Issue
Block a user