Skip to content

Commit

Permalink
Remove colorMode from shell state
Browse files Browse the repository at this point in the history
  • Loading branch information
estrattonbailey committed Nov 7, 2023
1 parent d9fa42f commit 081ce0c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 34 deletions.
4 changes: 0 additions & 4 deletions src/state/models/root-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export class RootStoreModel {
session: this.session.serialize(),
me: this.me.serialize(),
onboarding: this.onboarding.serialize(),
shell: this.shell.serialize(),
preferences: this.preferences.serialize(),
invitedUsers: this.invitedUsers.serialize(),
mutedThreads: this.mutedThreads.serialize(),
Expand All @@ -99,9 +98,6 @@ export class RootStoreModel {
if (hasProp(v, 'session')) {
this.session.hydrate(v.session)
}
if (hasProp(v, 'shell')) {
this.shell.hydrate(v.shell)
}
if (hasProp(v, 'preferences')) {
this.preferences.hydrate(v.preferences)
}
Expand Down
30 changes: 0 additions & 30 deletions src/state/models/ui/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ import {AppBskyEmbedRecord, AppBskyActorDefs, ModerationUI} from '@atproto/api'
import {RootStoreModel} from '../root-store'
import {makeAutoObservable, runInAction} from 'mobx'
import {ProfileModel} from '../content/profile'
import {isObj, hasProp} from 'lib/type-guards'
import {Image as RNImage} from 'react-native-image-crop-picker'
import {ImageModel} from '../media/image'
import {ListModel} from '../content/list'
import {GalleryModel} from '../media/gallery'
import {StyleProp, ViewStyle} from 'react-native'
import {isWeb} from 'platform/detection'

export type ColorMode = 'system' | 'light' | 'dark'

Expand Down Expand Up @@ -265,7 +263,6 @@ export interface ComposerOpts {
}

export class ShellUiModel {
colorMode: ColorMode = 'system'
isModalActive = false
activeModals: Modal[] = []
isLightboxActive = false
Expand All @@ -276,40 +273,13 @@ export class ShellUiModel {

constructor(public rootStore: RootStoreModel) {
makeAutoObservable(this, {
serialize: false,
rootStore: false,
hydrate: false,
})

this.setupClock()
this.setupLoginModals()
}

serialize(): unknown {
return {
colorMode: this.colorMode,
}
}

hydrate(v: unknown) {
if (isObj(v)) {
if (hasProp(v, 'colorMode') && isColorMode(v.colorMode)) {
this.setColorMode(v.colorMode)
}
}
}

setColorMode(mode: ColorMode) {
this.colorMode = mode

if (isWeb && typeof window !== 'undefined') {
const html = window.document.documentElement
// remove any other color mode classes
html.className = html.className.replace(/colorMode--\w+/g, '')
html.classList.add(`colorMode--${mode}`)
}
}

/**
* returns true if something was closed
* (used by the android hardware back btn)
Expand Down
8 changes: 8 additions & 0 deletions src/state/persisted/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {schema, Schema} from '#/state/persisted/schema'
import {migrate} from '#/state/persisted/legacy'
import * as store from '#/state/persisted/store'
import BroadcastChannel from '#/state/persisted/broadcast'
import {isWeb} from '#/platform/detection'

export type {Schema} from '#/state/persisted/schema'
export {schema} from '#/state/persisted/schema'
Expand Down Expand Up @@ -110,6 +111,13 @@ export function Provider({
_write(next)
return next
})

if (isWeb && typeof window !== 'undefined') {
const html = window.document.documentElement
// remove any other color mode classes
html.className = html.className.replace(/colorMode--\w+/g, '')
html.classList.add(`colorMode--${colorMode}`)
}
},
[_write, setState],
)
Expand Down

0 comments on commit 081ce0c

Please sign in to comment.