feat: add setting for notification list style
This commit is contained in:
parent
71994be407
commit
fc138609a1
24 changed files with 257 additions and 29 deletions
40
src/providers/UserPreferencesProvider.tsx
Normal file
40
src/providers/UserPreferencesProvider.tsx
Normal 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>
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue