-
-
Notifications
You must be signed in to change notification settings - Fork 688
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): add laf site setting config
- Loading branch information
Showing
8 changed files
with
138 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// @ts-ignore | ||
/* eslint-disable */ | ||
/////////////////////////////////////////////////////////////////////// | ||
// // | ||
// this file is autogenerated by service-generate // | ||
// do not edit this file manually // | ||
// // | ||
/////////////////////////////////////////////////////////////////////// | ||
/// <reference path = "api-auto.d.ts" /> | ||
import request from "@/utils/request"; | ||
import useGlobalStore from "@/pages/globalStore"; | ||
|
||
/** | ||
* Get site settings | ||
*/ | ||
export async function SettingControllerGetSettings( | ||
params: Paths.SettingControllerGetSettings.BodyParameters | any, | ||
): Promise<Paths.SettingControllerGetSettings.Responses> { | ||
// /v1/settings | ||
let _params: { [key: string]: any } = { | ||
appid: useGlobalStore.getState().currentApp?.appid || "", | ||
...params, | ||
}; | ||
return request(`/v1/settings`, { | ||
method: "GET", | ||
params: params, | ||
}); | ||
} | ||
|
||
/** | ||
* Get one site setting by key | ||
*/ | ||
export async function SettingControllerGetSettingByKey( | ||
params: Paths.SettingControllerGetSettingByKey.BodyParameters | any, | ||
): Promise<Paths.SettingControllerGetSettingByKey.Responses> { | ||
// /v1/settings/{key} | ||
let _params: { [key: string]: any } = { | ||
appid: useGlobalStore.getState().currentApp?.appid || "", | ||
...params, | ||
}; | ||
return request(`/v1/settings/${_params.key}`, { | ||
method: "GET", | ||
params: params, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { create } from "zustand"; | ||
import { devtools, persist } from "zustand/middleware"; | ||
import { immer } from "zustand/middleware/immer"; | ||
|
||
import { TSetting } from "@/apis/typing"; | ||
import { SettingControllerGetSettings } from "@/apis/v1/settings"; | ||
|
||
type SITE_KEY = "site_footer"; | ||
|
||
type State = { | ||
siteSettings: { | ||
// eslint-disable-next-line no-unused-vars | ||
[key in SITE_KEY]?: TSetting; | ||
}; | ||
getSiteSettings: () => void; | ||
}; | ||
|
||
const useSiteSettingStore = create<State>()( | ||
devtools( | ||
persist( | ||
immer((set, get) => ({ | ||
siteSettings: {}, | ||
getSiteSettings: async () => { | ||
const settings = await SettingControllerGetSettings({}); | ||
set((state) => { | ||
// convert array to object | ||
state.siteSettings = settings.data.reduce( | ||
(acc: { [x: string]: TSetting }, cur: TSetting) => { | ||
acc[cur.key] = cur; | ||
return acc; | ||
}, | ||
{} as Record<string, TSetting>, | ||
); | ||
}); | ||
}, | ||
})), | ||
|
||
{ | ||
name: "laf_site_settings", | ||
version: 1, | ||
}, | ||
), | ||
), | ||
); | ||
|
||
export default useSiteSettingStore; |