woodpecker/web/src/compositions/useUserConfig.ts
qwerty287 849e05bb8b
Rename build to pipeline in code (#1224)
Ref:  #745

Co-authored-by: Anbraten <anton@ju60.de>
Co-authored-by: 6543 <6543@obermui.de>
2022-10-18 03:24:12 +02:00

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),
});