Skip to content

Commit

Permalink
Fix maint mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sceuick committed Jun 29, 2023
1 parent de4e50f commit eceaa88
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
3 changes: 3 additions & 0 deletions common/types/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export namespace AppSchema {

export interface User {
_id: string

updatedAt?: string

kind: 'user'
username: string
hash: string
Expand Down
10 changes: 7 additions & 3 deletions srv/api/user/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ import { UI } from '/common/types'
import { publishOne } from '../ws/handle'

export const getInitialLoad = handle(async ({ userId }) => {
const [profile, user, presets, config, books] = await Promise.all([
const appConfig = await getAppConfig()
if (config.ui.maintenance) {
return { config: appConfig }
}

const [profile, user, presets, books] = await Promise.all([
store.users.getProfile(userId!),
getSafeUserConfig(userId!),
store.presets.getUserPresets(userId!),
getAppConfig(),
store.memory.getBooks(userId!),
])

return { profile, user, presets, config, books }
return { profile, user, presets, config: appConfig, books }
})

export const getProfile = handle(async ({ userId, params }) => {
Expand Down
4 changes: 2 additions & 2 deletions srv/db/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ export async function updateUserUI(userId: string, props: Partial<AppSchema.User
if (!prev) throw errors.Unauthorized

const next: AppSchema.User['ui'] = { ...prev.ui!, ...props }
await db('user').updateOne({ _id: userId }, { $set: { ui: next } })
await db('user').updateOne({ _id: userId }, { $set: { ui: next, updatedAt: now() } })
}

export async function updateUser(userId: string, props: Partial<AppSchema.User>) {
await db('user').updateOne({ userId }, { $set: props })
await db('user').updateOne({ userId }, { $set: { ...props, updatedAt: now() } })
return getUser(userId)
}

Expand Down
7 changes: 6 additions & 1 deletion web/store/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ export const settingStore = createStore<SettingState>(

if (res.result) {
setAssetPrefix(res.result.config.assetPrefix)
events.emit(EVENTS.init, res.result)

const isMaint = res.result.config?.maintenance
if (!isMaint) {
events.emit(EVENTS.init, res.result)
}

yield { init: res.result, config: res.result.config }

const maint = res.result.config?.maintenance
Expand Down

0 comments on commit eceaa88

Please sign in to comment.