Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theme Preferences #418

Merged
merged 2 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/selfish-adults-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'mexit-webapp': patch
---

Theme Preferences Changes
5 changes: 3 additions & 2 deletions apps/webapp/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ const FORCE_LOGOUT_VERSION = '0.21.0'

const AutoThemeSwitch = () => {
const theme = useUserPreferenceStore((state) => state.theme)
const hasHydrated = useUserPreferenceStore((s) => s._hasHydrated)
const { preferences, changeTheme } = useThemeContext()

useEffect(() => {
if (theme) {
if (theme && hasHydrated) {
if (theme !== preferences) {
changeTheme(theme.themeId, theme.mode)
}
}
}, [theme])
}, [theme, hasHydrated])

return null
}
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/Components/Init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Init = () => {
const { initCognito } = useAuth()
useEffect(() => {
API.init()
console.log('API_BASE_URLS', { config })
// console.log('API_BASE_URLS', { config })
const initUserAndApp = () => {
initCognito(
{
Expand Down
18 changes: 14 additions & 4 deletions apps/webapp/src/Hooks/useInitLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const useInitLoader = () => {
const contentStoreHydrated = useContentStore((store) => store._hasHydrated)
const initHighlightBlockMap = useHighlightStore((store) => store.initHighlightBlockMap)
const userPrefHydrated = useUserPreferenceStore((s) => s._hasHydrated)
const linksStoreHydrated = useLinkStore((s) => s._hasHydrated)

const { getAllSnippetsByWorkspace } = useApi()
const { getAllNamespaces } = useNamespaceApi()
Expand Down Expand Up @@ -108,9 +109,9 @@ export const useInitLoader = () => {
archive: useDataStore.getState().archive,
sharedNodes: useDataStore.getState().sharedNodes,
snippets: useSnippetStore.getState().snippets,
links: useLinkStore.getState().links,
links: useLinkStore.getState().links ?? [],
contents: useContentStore.getState().contents,
highlights: useHighlightStore.getState().highlights,
highlights: useHighlightStore.getState().highlights ?? [],
prompts: usePromptStore.getState().getAllPrompts()
}

Expand All @@ -126,7 +127,8 @@ export const useInitLoader = () => {
snippetHydrated &&
dataStoreHydrated &&
contentStoreHydrated &&
highlightStoreHydrated
highlightStoreHydrated &&
linksStoreHydrated
) {
startWorkers()
.then(async () => {
Expand All @@ -145,5 +147,13 @@ export const useInitLoader = () => {
console.error('InitSearchIndexError', { error })
})
}
}, [initalizeApp, snippetHydrated, dataStoreHydrated, contentStoreHydrated])
}, [
initalizeApp,
linksStoreHydrated,
highlightStoreHydrated,
snippetHydrated,
userPrefHydrated,
dataStoreHydrated,
contentStoreHydrated
])
}
2 changes: 1 addition & 1 deletion apps/webapp/src/Hooks/useSyncUserPreferences.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect } from 'react'

import { mergeUserPreferences, useAuthStore , userPreferenceStore as useUserPreferenceStore } from '@mexit/core'
import { mergeUserPreferences, useAuthStore, userPreferenceStore as useUserPreferenceStore } from '@mexit/core'

import { useUserService } from './API/useUserAPI'

Expand Down
9 changes: 6 additions & 3 deletions libs/core/src/Stores/preference.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface UserPreferenceStore extends UserPreferences {

export const preferenceStoreConfig = (set, get): UserPreferenceStore => ({
version: 'unset',
theme: { themeId: 'xeM', mode: 'dark' },
theme: { themeId: 'xem', mode: 'dark' },
lastOpenedNotes: {},
lastUsedSnippets: {},
space: {},
Expand All @@ -50,7 +50,6 @@ export const preferenceStoreConfig = (set, get): UserPreferenceStore => ({
version: 'unset',
activeNamespace: undefined,
space: {},
theme: { themeId: 'xeM', mode: 'dark' },
lastOpenedNotes: {},
lastUsedSnippets: {},
smartCaptureExcludedFields: {}
Expand Down Expand Up @@ -138,6 +137,7 @@ export const mergeUserPreferences = (local: UserPreferences, remote: UserPrefere
})

const mergedSpacePreferences = merge(local.space, remote.space ?? {})
const theme = remote.theme ?? local.theme

// mog('mergedLastOpenedNotes', { localLastOpenedNotes, mergedLastOpenedNotes, local, remote })
return {
Expand All @@ -148,7 +148,10 @@ export const mergeUserPreferences = (local: UserPreferences, remote: UserPrefere
lastOpenedNotes: getLimitedEntries({ ...local.lastOpenedNotes, ...mergedLastOpenedNotes }),
lastUsedSnippets: { ...local.lastUsedSnippets, ...mergedLastUsedSnippets },
space: mergedSpacePreferences,
theme: remote.theme ?? local.theme,
theme: {
...theme,
themeId: theme.themeId.toLowerCase()
},
smartCaptureExcludedFields: local.smartCaptureExcludedFields
}
}
Expand Down
2 changes: 1 addition & 1 deletion libs/core/src/Utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function wrapErr<T>(f: (result: T) => void) {

export const defaultContent: NodeContent = {
type: 'init',
content: [{ type: ELEMENT_PARAGRAPH, children: [{ text: 'hello world' }] }],
content: [{ type: ELEMENT_PARAGRAPH, children: [{ text: '' }] }],
version: -1
}

Expand Down