mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-16 21:46:32 +00:00
849e05bb8b
Ref: #745 Co-authored-by: Anbraten <anton@ju60.de> Co-authored-by: 6543 <6543@obermui.de>
32 lines
776 B
TypeScript
32 lines
776 B
TypeScript
import { computed, ref } from 'vue';
|
|
|
|
const USER_CONFIG_KEY = 'woodpecker-user-config';
|
|
|
|
type UserConfig = {
|
|
isPipelineFeedOpen: boolean;
|
|
redirectUrl: string;
|
|
};
|
|
|
|
const defaultUserConfig: UserConfig = {
|
|
isPipelineFeedOpen: false,
|
|
redirectUrl: '',
|
|
};
|
|
|
|
function loadUserConfig(): UserConfig {
|
|
const lsData = localStorage.getItem(USER_CONFIG_KEY);
|
|
if (!lsData) {
|
|
return defaultUserConfig;
|
|
}
|
|
|
|
return JSON.parse(lsData);
|
|
}
|
|
|
|
const config = ref<UserConfig>(loadUserConfig());
|
|
|
|
export default () => ({
|
|
setUserConfig<T extends keyof UserConfig>(key: T, value: UserConfig[T]): void {
|
|
config.value = { ...config.value, [key]: value };
|
|
localStorage.setItem(USER_CONFIG_KEY, JSON.stringify(config.value));
|
|
},
|
|
userConfig: computed(() => config.value),
|
|
});
|