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

@@ -25,7 +25,6 @@ class UserConfigType(TypedDict, total=False):
hide_watched: bool
show_ignored_only: bool
show_subed_only: bool
sponsorblock_id: str
class UserConfig:
@@ -44,7 +43,6 @@ class UserConfig:
hide_watched=False,
show_ignored_only=False,
show_subed_only=False,
sponsorblock_id=None,
)
VALID_STYLESHEETS = get_stylesheets()
@@ -134,9 +132,15 @@ class UserConfig:
es_document_path = f"ta_config/_doc/user_{self._user_id}"
response, status = ElasticWrap(es_document_path).get(print_error=False)
if status == 200 and "_source" in response.keys():
source = response.get("_source")
source = response.get("_source", {})
if "config" in source.keys():
return source.get("config")
# There is no config in ES
return {}
response, status_code = ElasticWrap(es_document_path).put(
{"config": dict(self._DEFAULT_USER_SETTINGS)}
)
if status_code == 200:
print(f"set default config for user {self._user_id}: {response}")
return self._DEFAULT_USER_SETTINGS