kickoff library item

This commit is contained in:
Dr-Blank 2024-05-09 23:23:50 -04:00
parent f8597f7430
commit 6c60d1c6ed
No known key found for this signature in database
GPG key ID: 7452CC63F210A266
13 changed files with 439 additions and 99 deletions

View file

@ -83,19 +83,20 @@ class PersonalizedView extends _$PersonalizedView {
final apiSettings = ref.watch(apiSettingsProvider);
final user = apiSettings.activeUser;
if (apiSettings.activeLibraryId == null) {
// set it to default user library by logging in and getting the library id
final login =
await api.login(username: user!.username!, password: user.password!);
// set it to default user library by logging in and getting the library id
final login =
await api.login(username: user!.username!, password: user.password!);
ref.read(apiSettingsProvider.notifier).updateState(
apiSettings.copyWith(activeLibraryId: login!.userDefaultLibraryId),
);
}
}
// try to find in cache
// final cacheKey = 'personalizedView:${apiSettings.activeLibraryId}';
var key = 'personalizedView:${apiSettings.activeLibraryId! + user!.id!}';
final cachedRes = await apiResponseCacheManager.getFileFromCache(
key,
);
final cachedRes = await apiResponseCacheManager.getFileFromMemory(
key,
) ??
await apiResponseCacheManager.getFileFromCache(key);
if (cachedRes != null) {
final resJson = jsonDecode(await cachedRes.file.readAsString()) as List;
final res = [
@ -107,8 +108,8 @@ class PersonalizedView extends _$PersonalizedView {
}
// ! exagerated delay
await Future.delayed(const Duration(seconds: 2));
final res = await api.libraries
// await Future.delayed(const Duration(seconds: 2));
final res = await api.libraries
.getPersonalized(libraryId: apiSettings.activeLibraryId!);
// debugPrint('personalizedView: ${res!.map((e) => e).toSet()}');
// save to cache