11import { defineStore } from "pinia" ;
2- import { useSettings } from "../../lib/use-settings " ;
2+ import { REST_API_URL } from "../../lib/io/constants " ;
33import type { TSettings } from "../../types" ;
44import { THEME_MODES } from "./constants" ;
55import {
@@ -16,29 +16,37 @@ import {
1616export const useSettingsStore = defineStore ( "settingsStore" , {
1717 state : ( ) => ( {
1818 apiVersion : '' ,
19- auth : {
20- isEnabled : false ,
21- loginUrl : '/login' ,
22- } ,
19+ isFetched : false ,
20+ isAuthEnabled : false ,
21+ authLogicUrl : '/login' ,
2322 codeEditor : getStoredPrimaryCodeEditor ( ) || 'phpstorm' ,
2423 themeType : getStoredActiveTheme ( ) ,
2524 isFixedHeader : getStoredFixedHeader ( ) ,
2625 isVisibleEventCounts : getStoredEventsCountVisibility ( ) ,
2726 } ) ,
2827 actions : {
29- initialize ( ) {
30- const { api : { getSettings } } = useSettings ( ) ;
28+ async fetchSettings ( ) {
29+ // TODO: need to remove fetch out of the store
30+ const settings : TSettings = await fetch ( `${ REST_API_URL } /api/settings` )
31+ . then ( ( response ) => response . json ( ) )
32+ . catch ( ( e ) => {
33+ console . error ( e ) ;
34+
35+ return null
36+ } ) ;
37+
38+ if ( settings . version ) {
39+ this . apiVersion = settings . version
40+ }
41+
42+ if ( settings . auth ) {
43+ this . isAuthEnabled = settings . auth . enabled ;
44+ this . authLogicUrl = settings . auth . login_url ;
45+ }
3146
32- getSettings ( ) . then ( ( { version, auth } = { } as TSettings ) => {
33- if ( version ) {
34- this . apiVersion = version
35- }
47+ this . isFetched = true
3648
37- if ( auth ) {
38- this . auth . isEnabled = auth . enabled ;
39- this . auth . loginUrl = auth . login_url ;
40- }
41- } )
49+ return settings
4250 } ,
4351 changeTheme ( ) {
4452 this . themeType = this . themeType === THEME_MODES . DARK
0 commit comments