Feat global state (#861)

* add zustand, add auth store

* add user config store, isAdmin from store

* move ColourVariants, fix importColours

* get userConfig from store

* fix name conflict

* home filter bar from config store

* use user store for channel list

* use userConfig store for channel pages

* use userConfig for playlist pages

* fix channel video type navigation

* use userConfig update on downloads page

* fix view style in search

* handle initial user config, take 2

* modify userSettings in global state
This commit is contained in:
Simon
2025-01-06 19:44:05 +07:00
committed by GitHub
parent 0eca242fd6
commit c9607343e6
31 changed files with 443 additions and 721 deletions

View File

@@ -1,4 +1,3 @@
import { ColourVariants } from '../../configuration/colours/getColours';
import { SortByType, SortOrderType, ViewLayoutType } from '../../pages/Home';
import getApiUrl from '../../configuration/getApiUrl';
import defaultHeaders from '../../configuration/defaultHeaders';
@@ -16,23 +15,24 @@ export type UserMeType = {
config: UserConfigType;
};
export type ColourVariants = 'dark.css' | 'light.css' | 'matrix.css' | 'midnight.css';
export type UserConfigType = {
stylesheet?: ColourVariants;
page_size?: number;
sort_by?: SortByType;
sort_order?: SortOrderType;
view_style_home?: ViewLayoutType;
view_style_channel?: ViewLayoutType;
view_style_downloads?: ViewLayoutType;
view_style_playlist?: ViewLayoutType;
grid_items?: number;
hide_watched?: boolean;
show_ignored_only?: boolean;
show_subed_only?: boolean;
sponsorblock_id?: number;
stylesheet: ColourVariants;
page_size: number;
sort_by: SortByType;
sort_order: SortOrderType;
view_style_home: ViewLayoutType;
view_style_channel: ViewLayoutType;
view_style_downloads: ViewLayoutType;
view_style_playlist: ViewLayoutType;
grid_items: number;
hide_watched: boolean;
show_ignored_only: boolean;
show_subed_only: boolean;
};
const updateUserConfig = async (config: UserConfigType): Promise<UserConfigType> => {
const updateUserConfig = async (config: Partial<UserConfigType>): Promise<UserConfigType> => {
const apiUrl = getApiUrl();
const csrfCookie = getCookie('csrftoken');