-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { PlatformVariant } from "lib/shopify/types" | ||
import type { CommerceProduct } from "types" | ||
import type { Combination } from "utils/product-options-utils" | ||
import { create } from "zustand" | ||
|
||
interface AddProductStore { | ||
product: CommerceProduct | null | ||
combination: Combination | null | ||
setProduct: ({ product, combination }: { product: CommerceProduct; combination: Combination | PlatformVariant }) => void | ||
clean: () => void | ||
} | ||
|
||
export const useAddProductStore = create<AddProductStore>((set) => ({ | ||
product: null, | ||
combination: null, | ||
setProduct: ({ product, combination }) => set(() => ({ product, combination })), | ||
clean: () => set(() => ({ product: null, combination: null })), | ||
})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { PlatformCart } from "lib/shopify/types" | ||
import { create } from "zustand" | ||
|
||
interface CartStore { | ||
isOpen: boolean | ||
isSheetLoaded: boolean | ||
lastUpdatedAt: number | ||
cart: PlatformCart | null | ||
|
||
openCart: () => void | ||
closeCart: () => void | ||
preloadSheet: () => void | ||
refresh: () => void | ||
setCart: (payload: PlatformCart | null) => void | ||
} | ||
|
||
export const useCartStore = create<CartStore>((set) => ({ | ||
isOpen: false, | ||
lastUpdatedAt: 0, | ||
cart: null, | ||
isSheetLoaded: false, | ||
|
||
openCart: () => set(() => ({ isOpen: true, isSheetLoaded: true, lastUpdatedAt: Date.now() })), | ||
closeCart: () => set(() => ({ isOpen: false, isSheetLoaded: true, lastUpdatedAt: Date.now() })), | ||
preloadSheet: () => set(() => ({ isSheetLoaded: true })), | ||
refresh: () => set(() => ({ lastUpdatedAt: Date.now() })), | ||
setCart: (payload: PlatformCart | null) => set(() => ({ cart: payload })), | ||
})) |
11 changes: 11 additions & 0 deletions
11
starters/shopify-algolia/stores/filter-transition-store.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { create } from "zustand" | ||
|
||
interface FilterTransitionStore { | ||
selected: string[] | ||
set: (filter: string) => void | ||
} | ||
|
||
export const useFilterTransitionStore = create<FilterTransitionStore>((set) => ({ | ||
selected: [], | ||
set: (filter: string) => set((prev) => ({ selected: [...prev.selected, filter] })), | ||
})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { create } from "zustand" | ||
|
||
type FilterStatus = "idle" | "hidden" | "visible" | ||
|
||
interface FilterStore { | ||
status: FilterStatus | ||
set: (value: FilterStatus) => void | ||
} | ||
|
||
export const useFilterStore = create<FilterStore>((set) => ({ | ||
status: "idle", | ||
set: (value: FilterStatus) => set(() => ({ status: value })), | ||
})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { create } from "zustand" | ||
|
||
export type Modal = "login" | "signup" | "search" | "facets-mobile" | "review" | ||
|
||
interface ModalStore { | ||
modals: Partial<Record<Modal, boolean>> | ||
openModal: (modal: Modal) => void | ||
closeModal: (modal: Modal) => void | ||
closeAllModals: () => void | ||
} | ||
|
||
export const useModalStore = create<ModalStore>((set) => ({ | ||
modals: {}, | ||
|
||
openModal: (modalId: Modal) => | ||
set((state) => ({ | ||
modals: { ...state.modals, [modalId]: true }, | ||
})), | ||
|
||
closeModal: (modalId: Modal) => | ||
set((state) => ({ | ||
modals: { ...state.modals, [modalId]: false }, | ||
})), | ||
|
||
closeAllModals: () => | ||
set((state) => ({ | ||
modals: Object.keys(state.modals).reduce( | ||
(acc, modalId) => { | ||
acc[modalId as Modal] = false | ||
return acc | ||
}, | ||
{} as Record<Modal, boolean> | ||
), | ||
})), | ||
})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { PlatformUser } from "lib/shopify/types" | ||
import { create } from "zustand" | ||
|
||
interface UserStore { | ||
user: PlatformUser | null | ||
setUser: (payload: PlatformUser | null) => void | ||
} | ||
|
||
export const useUserStore = create<UserStore>((set) => ({ | ||
user: null, | ||
setUser: (payload: PlatformUser | null) => set(() => ({ user: payload })), | ||
})) |