feat: add setting for notification list style

This commit is contained in:
codytseng 2025-09-06 13:49:13 +08:00
parent 71994be407
commit fc138609a1
24 changed files with 257 additions and 29 deletions

View file

@ -0,0 +1,40 @@
import storage from '@/services/local-storage.service'
import { TNotificationStyle } from '@/types'
import { createContext, useContext, useState } from 'react'
type TUserPreferencesContext = {
notificationListStyle: TNotificationStyle
updateNotificationListStyle: (style: TNotificationStyle) => void
}
const UserPreferencesContext = createContext<TUserPreferencesContext | undefined>(undefined)
export const useUserPreferences = () => {
const context = useContext(UserPreferencesContext)
if (!context) {
throw new Error('useUserPreferences must be used within a UserPreferencesProvider')
}
return context
}
export function UserPreferencesProvider({ children }: { children: React.ReactNode }) {
const [notificationListStyle, setNotificationListStyle] = useState(
storage.getNotificationListStyle()
)
const updateNotificationListStyle = (style: TNotificationStyle) => {
setNotificationListStyle(style)
storage.setNotificationListStyle(style)
}
return (
<UserPreferencesContext.Provider
value={{
notificationListStyle,
updateNotificationListStyle
}}
>
{children}
</UserPreferencesContext.Provider>
)
}