woodpecker/web/src/compositions/useUserConfig.ts
Anbraten 70af29f9a2
fix redirect after login (#824)
if you are in buildView and login, go back to this buildView again
2022-05-14 17:45:01 +02:00

33 lines
770 B
TypeScript

import { computed, ref } from 'vue';
const USER_CONFIG_KEY = 'woodpecker-user-config';
type UserConfig = {
isBuildFeedOpen: boolean;
redirectUrl: string;
};
const defaultUserConfig: UserConfig = {
isBuildFeedOpen: 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),
});