Skip to content

Commit

Permalink
feat: take reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
xlecunff-pass committed Jan 8, 2025
1 parent 7b51294 commit 11cc946
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/features/identityCheck/api/useCreditActivation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const defaultState: CreditState = {
activationDate: undefined,
}

const useCreditStore = createStore('credit', defaultState, { persist: true })
const useCreditStore = createStore({ name: 'credit', defaultState, options: { persist: true } })

export const creditActions = createActions(useCreditStore, (set) => ({
setActivationDate: (date: Date) => set({ activationDate: date }),
setActivationDate: (activationDate: Date) => set({ activationDate }),
}))
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ type State = {

const defaultState: State = { address: null }

const useAddressStore = createStore('profile-address', defaultState, { persist: true })
const useAddressStore = createStore({
name: 'profile-address',
defaultState,
options: { persist: true },
})

export const addressActions = createActions(useAddressStore, (set) => ({
setAddress: (payload: string) => set({ address: payload }),
setAddress: (address: string) => set({ address }),
resetAddress: () => set(defaultState),
}))

Expand Down
10 changes: 7 additions & 3 deletions src/features/identityCheck/pages/profile/store/cityStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ type State = { city: SuggestedCity | null }

const defaultState: State = { city: null }

const useCityStore = createStore('profile-city', defaultState, {
persist: true,
const useCityStore = createStore({
name: 'profile-city',
defaultState,
options: {
persist: true,
},
})

export const useCity = () => useCityStore((state) => state.city)

export const cityActions = createActions(useCityStore, (set) => ({
setCity: (payload: SuggestedCity) => set({ city: payload }),
setCity: (city: SuggestedCity) => set({ city }),
resetCity: () => set(defaultState),
}))
4 changes: 2 additions & 2 deletions src/features/identityCheck/pages/profile/store/nameStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ type State = { name: Name | null }

const defaultState: State = { name: null }

const useNameStore = createStore('profile-name', defaultState, { persist: true })
const useNameStore = createStore({ name: 'profile-name', defaultState, options: { persist: true } })

export const useName = () => useNameStore((state) => state.name)

export const nameActions = createActions(useNameStore, (set) => ({
setName: (payload: Name) => set({ name: payload }),
setName: (name: Name) => set({ name }),
resetName: () => set(defaultState),
}))
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { render, screen } from 'tests/utils'
import { SingleFilterBannerContainer } from './SingleFilterBannerContainer'

jest.mock('features/venueMap/store/venueTypeCodeStore')
const mockUseVenueTypeCode = useVenueTypeCode as jest.Mock
const mockUseVenueTypeCode = useVenueTypeCode

const VENUE_TYPE = VenueTypeCodeKey.MOVIE

Expand Down
8 changes: 6 additions & 2 deletions src/features/venueMap/store/initialVenuesStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ type State = {

const defaultState: State = { initialVenues: [] }

const useInitialVenuesStore = createStore('venue-map-store', defaultState, { persist: true })
const useInitialVenuesStore = createStore({
name: 'venue-map-store',
defaultState,
options: { persist: true },
})

export const useInitialVenues = () => useInitialVenuesStore((state) => state.initialVenues)

export const initialVenuesActions = createActions(useInitialVenuesStore, (set) => ({
setInitialVenues: (payload: Venue[]) => set({ initialVenues: payload }),
setInitialVenues: (initialVenues: Venue[]) => set({ initialVenues }),
}))
13 changes: 5 additions & 8 deletions src/features/venueMap/store/selectedVenueStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ type State = {

const defaultState: State = { selectedVenue: null }

const useSelectedVenueStore = createStore('venue-map-selected-venue', defaultState)
const useSelectedVenueStore = createStore({ name: 'venue-map-selected-venue', defaultState })

export const useSelectedVenue = () => useSelectedVenueStore((state) => state.selectedVenue)

export const selectedVenueActions = createActions(
useSelectedVenueStore,
(set: (payload: State) => void) => ({
setSelectedVenue: (payload: GeolocatedVenue) => set({ selectedVenue: payload }),
removeSelectedVenue: () => set(defaultState),
})
)
export const selectedVenueActions = createActions(useSelectedVenueStore, (set) => ({
setSelectedVenue: (selectedVenue: GeolocatedVenue) => set({ selectedVenue }),
removeSelectedVenue: () => set(defaultState),
}))
2 changes: 1 addition & 1 deletion src/features/venueMap/store/venueTypeCodeStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type State = {

const defaultState: State = { venueTypeCode: null }

const useVenueTypeCodeStore = createStore('venue-map-venue-type-code', defaultState)
const useVenueTypeCodeStore = createStore({ name: 'venue-map-venue-type-code', defaultState })

export const useVenueTypeCode = () => useVenueTypeCodeStore((state) => state.venueTypeCode)
export const venueTypeCodeActions = createActions(useVenueTypeCodeStore, (set) => ({
Expand Down
12 changes: 6 additions & 6 deletions src/features/venueMap/store/venuesFilterStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ const defaultState: State = {
venuesFilters: [],
}

const useVenuesFilterStore = createStore('venue-VenuesFilterilter', defaultState)
const useVenuesFilterStore = createStore({ name: 'venue-filter', defaultState })

export const useVenuesFilter = () => useVenuesFilterStore((state) => state.venuesFilters)

export const venuesFilterActions = createActions(useVenuesFilterStore, (set) => ({
setVenuesFilters: (payload: VenueTypeCodeKey[]) => set((_) => ({ venuesFilters: payload })),
addVenuesFilters: (payload: VenueTypeCodeKey[]) =>
setVenuesFilters: (venuesFilters: VenueTypeCodeKey[]) => set((_) => ({ venuesFilters })),
addVenuesFilters: (VenueTypeCodeKeys: VenueTypeCodeKey[]) =>
set((state: State) => ({
venuesFilters: Array.from(new Set([...state.venuesFilters, ...payload])),
venuesFilters: Array.from(new Set([...state.venuesFilters, ...VenueTypeCodeKeys])),
})),
removeVenuesFilters: (payload: VenueTypeCodeKey[]) =>
removeVenuesFilters: (VenueTypeCodeKeys: VenueTypeCodeKey[]) =>
set((state: State) => ({
venuesFilters: difference(state.venuesFilters, payload),
venuesFilters: difference(state.venuesFilters, VenueTypeCodeKeys),
})),
reset: () => set((_) => ({ venuesFilters: [] })),
}))
6 changes: 3 additions & 3 deletions src/features/venueMap/store/venuesStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ type State = {

const defaultState: State = { venues: [] }

const useVenuesStore = createStore('venue-map-venues', defaultState)
const useVenuesStore = createStore({ name: 'venue-map-venues', defaultState })

export const useVenues = () => useVenuesStore((state) => state.venues)

export const venuesActions = createActions(useVenuesStore, (set: (payload: State) => void) => ({
setVenues: (payload: Venue[]) => set({ venues: payload }),
export const venuesActions = createActions(useVenuesStore, (set) => ({
setVenues: (venues: Venue[]) => set({ venues }),
}))
9 changes: 6 additions & 3 deletions src/libs/store/createActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ type Store<State> = UseBoundStore<StoreApi<State>>

type Actions<State, ActionsType> = (set: Store<State>['setState']) => ActionsType

// eslint-disable-next-line @typescript-eslint/no-explicit-any -- we don't want to restrict the payload type
export const createActions = <State, ActionsType extends Record<string, (...args: any[]) => void>>(
export const createActions = <
State,
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- we don't want to restrict the payload type
ActionsType extends Record<string, (...args: any[]) => void>,
>(
store: Store<State>,
actions: Actions<State, ActionsType>
): ActionsType => {
): Readonly<ActionsType> => {
return actions(store.setState)
}
9 changes: 7 additions & 2 deletions src/libs/store/createStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ type Options = {
persist?: boolean
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any -- we don't want to restrict the payload type
export const createStore = <State>(name: string, defaultState: State, options?: Options) => {
type Params<State> = {
name: string
defaultState: State
options?: Options
}

export const createStore = <State>({ name, defaultState, options }: Params<State>) => {
const store = () => defaultState
const persistedStore = persist(store, {
name,
Expand Down

0 comments on commit 11cc946

Please sign in to comment.