PluginProbe
Extendify / 0.10.2
Extendify v0.10.2
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Onboarding / state / UserSelections.js

UserSelections.js in Extendify 0.10.2, at src/Onboarding/state/UserSelections.js

90 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import create from 'zustand'
2 import { persist, devtools } from 'zustand/middleware'
3
4 const initialState = {
5 siteType: {},
6 siteInformation: {
7 title: undefined,
8 },
9 feedbackMissingSiteType: '',
10 feedbackMissingGoal: '',
11 exitFeedback: undefined,
12 siteTypeSearch: [],
13 style: null,
14 pages: [],
15 plugins: [],
16 goals: [],
17 }
18 const store = (set, get) => ({
19 ...initialState,
20 setSiteType(siteType) {
21 set({ siteType })
22 },
23 setSiteInformation(name, value) {
24 const siteInformation = { ...get().siteInformation, [name]: value }
25 set({ siteInformation })
26 },
27 setFeedbackMissingSiteType: (feedbackMissingSiteType) =>
28 set({ feedbackMissingSiteType }),
29 setFeedbackMissingGoal: (feedbackMissingGoal) =>
30 set({ feedbackMissingGoal }),
31 setExitFeedback: (exitFeedback) => set({ exitFeedback }),
32 has(type, item) {
33 if (!item?.id) return false
34 return get()[type].some((t) => t.id === item.id)
35 },
36 add(type, item) {
37 if (get().has(type, item)) return
38 set({ [type]: [...get()[type], item] })
39 },
40 remove(type, item) {
41 set({ [type]: get()[type]?.filter((t) => t.id !== item.id) })
42 },
43 reset(type) {
44 set({ [type]: [] })
45 },
46 toggle(type, item) {
47 if (get().has(type, item)) {
48 get().remove(type, item)
49 return
50 }
51 get().add(type, item)
52 },
53 setStyle(style) {
54 set({ style })
55 },
56 canLaunch() {
57 // The user can launch if they have a complete selection
58 return (
59 Object.keys(get()?.siteType ?? {})?.length > 0 &&
60 Object.keys(get()?.style ?? {})?.length > 0 &&
61 get()?.pages?.length > 0
62 )
63 },
64 resetState() {
65 set(initialState)
66 },
67 })
68
69 const withDevtools = devtools(store, {
70 name: 'Extendify Launch User Selection',
71 })
72 const withPersist = persist(withDevtools, {
73 name: 'extendify-site-selection',
74 getStorage: () => localStorage,
75 partialize: (state) => ({
76 siteType: state?.siteType ?? {},
77 siteInformation: state?.siteInformation ?? {},
78 feedbackMissingSiteType: state?.feedbackMissingSiteType ?? '',
79 feedbackMissingGoal: state?.feedbackMissingGoal ?? '',
80 siteTypeSearch: state?.siteTypeSearch ?? [],
81 style: state?.style ?? null,
82 pages: state?.pages ?? [],
83 plugins: state?.plugins ?? [],
84 goals: state?.goals ?? [],
85 }),
86 })
87 export const useUserSelectionStore = window?.extOnbData?.devbuild
88 ? create(withDevtools)
89 : create(withPersist)
90