⚡️ (user settings) cache user settings
This commit is contained in:
@@ -4,5 +4,6 @@ export enum DataType {
|
|||||||
Note = 'Note',
|
Note = 'Note',
|
||||||
BacklinkNote = 'BacklinkNote',
|
BacklinkNote = 'BacklinkNote',
|
||||||
RepetitionCard = 'RepetitionCard',
|
RepetitionCard = 'RepetitionCard',
|
||||||
History = 'History'
|
History = 'History',
|
||||||
|
UserSettings = 'UserSettings'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ class Data {
|
|||||||
return result?.ok ?? false
|
return result?.ok ?? false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await this.locale?.put(model)
|
const result = await this.locale?.put(model)
|
||||||
return result?.ok ?? false
|
return result?.ok ?? false
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
export interface UserSettings {
|
import { DataType } from '@/data/DataType.enum'
|
||||||
|
import { Model } from '@/data/models/Model'
|
||||||
|
|
||||||
|
export interface UserSettings extends Model<DataType.UserSettings> {
|
||||||
fontFamily?:
|
fontFamily?:
|
||||||
| 'Courgette'
|
| 'Courgette'
|
||||||
| 'IBM Plex Serif'
|
| 'IBM Plex Serif'
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
|
|
||||||
|
import { data } from '@/data/data'
|
||||||
|
import { DataType } from '@/data/DataType.enum'
|
||||||
import { RepoFile } from '@/modules/repo/interfaces/RepoFile'
|
import { RepoFile } from '@/modules/repo/interfaces/RepoFile'
|
||||||
import { UserSettings } from '@/modules/repo/interfaces/UserSettings'
|
import { UserSettings } from '@/modules/repo/interfaces/UserSettings'
|
||||||
import {
|
import {
|
||||||
@@ -32,10 +34,10 @@ export const useUserRepoStore = defineStore({
|
|||||||
needToLogin: false
|
needToLogin: false
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
async setUserRepo(newUser: string, newRepo: string) {
|
async setUserRepo(user: string, repo: string) {
|
||||||
this.isReadmeOffline = true
|
this.isReadmeOffline = true
|
||||||
this.user = newUser
|
this.user = user
|
||||||
this.repo = newRepo
|
this.repo = repo
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await refreshToken()
|
await refreshToken()
|
||||||
@@ -43,18 +45,37 @@ export const useUserRepoStore = defineStore({
|
|||||||
console.warn('impossible to refresh token')
|
console.warn('impossible to refresh token')
|
||||||
}
|
}
|
||||||
|
|
||||||
getFiles(newUser, newRepo)
|
const userSettingsId = `UserSetting-${user}-${repo}`
|
||||||
|
const cachedUserSettings = await data.get<
|
||||||
|
DataType.UserSettings,
|
||||||
|
UserSettings
|
||||||
|
>(userSettingsId)
|
||||||
|
|
||||||
|
if (cachedUserSettings) {
|
||||||
|
this.userSettings = cachedUserSettings
|
||||||
|
}
|
||||||
|
|
||||||
|
getFiles(user, repo)
|
||||||
.then((files) => {
|
.then((files) => {
|
||||||
this.files = files
|
this.files = files
|
||||||
return getUserSettingsContent(newUser, newRepo, files)
|
return getUserSettingsContent(user, repo, files)
|
||||||
})
|
})
|
||||||
.then((userSettings) => (this.userSettings = userSettings))
|
.then((userSettings) => {
|
||||||
|
this.userSettings = userSettings
|
||||||
|
|
||||||
getCachedMainReadme(newUser, newRepo)
|
if (userSettings) {
|
||||||
|
data.update<DataType.UserSettings, UserSettings>({
|
||||||
|
...userSettings,
|
||||||
|
_id: userSettingsId
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
getCachedMainReadme(user, repo)
|
||||||
.then((readme) => {
|
.then((readme) => {
|
||||||
this.readme = readme
|
this.readme = readme
|
||||||
})
|
})
|
||||||
.then(() => getMainReadme(newUser, newRepo))
|
.then(() => getMainReadme(user, repo))
|
||||||
.then((readme) => {
|
.then((readme) => {
|
||||||
this.readme = readme
|
this.readme = readme
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user