-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use gloabl currentSpace to track theming properly (#229)
- Loading branch information
Showing
6 changed files
with
78 additions
and
32 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
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,56 @@ | ||
import { SetterFunction, StoreGet, StoreSet } from "../../createStore"; | ||
import { AppStore } from ".."; | ||
import { SpaceConfig } from "@/common/components/templates/Space"; | ||
import { isNil, mapValues } from "lodash"; | ||
|
||
interface CurrentSpaceStoreState { | ||
currentSpaceId: string | null; | ||
} | ||
|
||
interface CurrentSpaceStoreActions { | ||
setCurrentSpaceId: SetterFunction<string | null>; | ||
getCurrentSpaceConfig: () => Omit<SpaceConfig, "isEditable"> | undefined; | ||
} | ||
|
||
const HOMEBASE_ID = "homebase"; | ||
|
||
export type CurrentSpaceStore = CurrentSpaceStoreState & | ||
CurrentSpaceStoreActions; | ||
|
||
export const currentSpaceStoreDefaults: CurrentSpaceStoreState = { | ||
currentSpaceId: HOMEBASE_ID, | ||
}; | ||
|
||
export const createCurrentSpaceStoreFunc = ( | ||
set: StoreSet<AppStore>, | ||
get: StoreGet<AppStore>, | ||
): CurrentSpaceStore => ({ | ||
...currentSpaceStoreDefaults, | ||
setCurrentSpaceId(id) { | ||
set((draft) => { | ||
draft.currentSpace.currentSpaceId = id; | ||
}, "setCurrentSpaceId"); | ||
}, | ||
getCurrentSpaceConfig: () => { | ||
const currentSpaceId = get().currentSpace.currentSpaceId; | ||
if (currentSpaceId === HOMEBASE_ID) return get().homebase.homebaseConfig; | ||
if (isNil(currentSpaceId)) return undefined; | ||
const currentSpaceUpdatableConfig = get().space.localSpaces[currentSpaceId]; | ||
return currentSpaceUpdatableConfig | ||
? { | ||
...currentSpaceUpdatableConfig, | ||
fidgetInstanceDatums: mapValues( | ||
currentSpaceUpdatableConfig.fidgetInstanceDatums, | ||
(datum) => ({ | ||
...datum, | ||
config: { | ||
settings: datum.config.settings, | ||
editable: datum.config.editable, | ||
data: {}, // TO DO: Inject fidget data here | ||
}, | ||
}), | ||
), | ||
} | ||
: undefined; | ||
}, | ||
}); |
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
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
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
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