@@ -4,7 +4,8 @@ import { Tag } from 'src/features/remoteConfig'
44import { enhanceTags } from 'src/utils/DataEnhancement'
55import { create } from 'zustand'
66import { persist } from 'zustand/middleware'
7- import { CardSettingsType , ListingMode , SelectedCard , SupportedCardType , Theme } from '../types'
7+ import { CardSettingsType , DNDDuration , ListingMode , SelectedCard , SupportedCardType , Theme } from '../types'
8+
89
910export type UserPreferencesState = {
1011 userSelectedTags : Tag [ ]
@@ -19,7 +20,7 @@ export type UserPreferencesState = {
1920 cardsSettings : Record < string , CardSettingsType >
2021 firstSeenDate : number
2122 userCustomCards : SupportedCardType [ ]
22- DNDDuration : number | "always"
23+ DNDDuration : DNDDuration
2324}
2425
2526type UserPreferencesStoreActions = {
@@ -35,7 +36,7 @@ type UserPreferencesStoreActions = {
3536 markOnboardingAsCompleted : ( occupation : Omit < Occupation , 'icon' > | null ) => void
3637 setUserCustomCards : ( cards : SupportedCardType [ ] ) => void
3738 updateCardOrder : ( prevIndex : number , newIndex : number ) => void
38- setDNDDuration : ( value : number | "always" ) => void
39+ setDNDDuration : ( value : DNDDuration ) => void
3940 isDNDModeActive : ( ) => boolean ;
4041}
4142
@@ -59,7 +60,7 @@ export const useUserPreferences = create(
5960 { id : 3 , name : 'producthunt' , type : 'supported' } ,
6061 ] ,
6162 userCustomCards : [ ] ,
62- DNDDuration : 0 ,
63+ DNDDuration : "never" ,
6364 setSearchEngine : ( searchEngine : string ) => set ( { searchEngine : searchEngine } ) ,
6465 setListingMode : ( listingMode : ListingMode ) => set ( { listingMode : listingMode } ) ,
6566 setTheme : ( theme : Theme ) => set ( { theme : theme } ) ,
@@ -95,13 +96,21 @@ export const useUserPreferences = create(
9596
9697 return { cards : newState }
9798 } ) ,
98- setDNDDuration : ( value ) => set ( { DNDDuration : value } ) ,
99+ setDNDDuration : ( value : DNDDuration ) => set ( { DNDDuration : value } ) ,
99100 isDNDModeActive : ( ) => {
100101 const duration = get ( ) . DNDDuration
101102 if ( duration === "always" ) {
102103 return true ;
104+ } else if ( typeof duration === "object" ) {
105+ const dndValue = duration as {
106+ value : number
107+ countdown : number
108+ }
109+ return Boolean ( dndValue . value && dndValue . countdown - new Date ( ) . getTime ( ) > 0 )
110+ } else {
111+ return false ;
103112 }
104- return Boolean ( duration && duration - new Date ( ) . getTime ( ) > 0 )
113+
105114 }
106115 } ) ,
107116 {
0 commit comments