|
1 | | -import { type HttpOptions } from 'sefirot/stores/HttpConfig' |
2 | | -import { useSetupHttp } from './Http' |
3 | | -import { type HasLang, useSetupLang } from './Lang' |
4 | | -import { type HasTheme, useSetupTheme } from './Theme' |
| 1 | +import { type HttpOptions, useHttpConfig } from '../stores/HttpConfig' |
| 2 | +import { type Lang, getBrowserLang, provideLang } from './Lang' |
| 3 | +import { type Theme, useTheme } from './Theme' |
5 | 4 |
|
6 | | -export interface SetupAppUser extends HasLang, HasTheme {} |
| 5 | +export interface SetupAppUser { |
| 6 | + lang?: Lang |
| 7 | + theme?: Theme |
| 8 | +} |
7 | 9 |
|
8 | 10 | export interface SetupAppOptions { |
9 | 11 | http?: HttpOptions |
10 | 12 | } |
11 | 13 |
|
12 | 14 | export function useSetupApp(): (user?: SetupAppUser | null, options?: SetupAppOptions) => void { |
13 | | - const setupLang = useSetupLang() |
14 | | - const setupTheme = useSetupTheme() |
15 | | - const setupHttp = useSetupHttp() |
| 15 | + const theme = useTheme() |
| 16 | + const httpConfig = useHttpConfig() |
16 | 17 |
|
17 | 18 | return (user, options) => { |
18 | | - setupLang(user) |
19 | | - setupTheme(user) |
20 | | - setupHttp(user, options?.http) |
| 19 | + const lang = user?.lang ?? getBrowserLang() |
| 20 | + provideLang(lang) |
| 21 | + if (user?.theme) { theme.value = user.theme } |
| 22 | + httpConfig.apply({ lang, ...options?.http }) |
21 | 23 | } |
22 | 24 | } |
0 commit comments