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,32 +16,37 @@ import {
1616export const useSettingsStore = defineStore ( "settingsStore" , {
1717 state : ( ) => ( {
1818 apiVersion : '' ,
19- isSettingsLoading : false ,
20- auth : {
21- isEnabled : false ,
22- loginUrl : '/login' ,
23- } ,
19+ isFetched : false ,
20+ isAuthEnabled : false ,
21+ authLogicUrl : '/login' ,
2422 codeEditor : getStoredPrimaryCodeEditor ( ) || 'phpstorm' ,
2523 themeType : getStoredActiveTheme ( ) ,
2624 isFixedHeader : getStoredFixedHeader ( ) ,
2725 isVisibleEventCounts : getStoredEventsCountVisibility ( ) ,
2826 } ) ,
2927 actions : {
30- async initialize ( ) {
31- this . isSettingsLoading = true
32- 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+ } ) ;
3337
34- const { version, auth } : TSettings = await getSettings ( )
35- if ( version ) {
36- this . apiVersion = version
38+ if ( settings . version ) {
39+ this . apiVersion = settings . version
3740 }
3841
39- if ( auth ) {
40- this . auth . isEnabled = auth . enabled ;
41- this . auth . loginUrl = auth . login_url ;
42+ if ( settings . auth ) {
43+ this . isAuthEnabled = settings . auth . enabled ;
44+ this . authLogicUrl = settings . auth . login_url ;
4245 }
4346
44- this . isSettingsLoading = false
47+ this . isFetched = true
48+
49+ return settings
4550 } ,
4651 changeTheme ( ) {
4752 this . themeType = this . themeType === THEME_MODES . DARK
0 commit comments