add library, tsconfig.base.json
This commit is contained in:
1 parent
0348f84255
commit
ffbe5fed18
8 files changed
+758
-25
No files matched your search
+55
-9
@@ -26,6 +26,16 @@ export interface IEntry {
|
||||
tag: string[]
|
||||
}
|
||||
|
||||
export interface ILibrary {
|
||||
id: string
|
||||
title: string
|
||||
list: string[]
|
||||
type: IType
|
||||
description: string
|
||||
tag: string[]
|
||||
isShared?: boolean
|
||||
}
|
||||
|
||||
export type ILookup<T> = T & {
|
||||
offset?: number
|
||||
limit?: number
|
||||
@@ -48,9 +58,9 @@ class Api {
|
||||
async setWanikaniApiKey(apiKey?: string) {
|
||||
const setApiKey = () => {
|
||||
if (apiKey) {
|
||||
this.axios.defaults.headers.common.Authorization = `Bearer ${apiKey}`
|
||||
this.axios.defaults.headers.common['Authorization'] = `Bearer ${apiKey}`
|
||||
} else {
|
||||
delete this.axios.defaults.headers.common.Authorization
|
||||
delete this.axios.defaults.headers.common['Authorization']
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,20 +109,17 @@ class Api {
|
||||
return r
|
||||
}
|
||||
|
||||
async user_updateSettings(u: {
|
||||
levelMin?: number
|
||||
level_browser?: ILevelBrowser
|
||||
}) {
|
||||
async user_updateSettings(u: Omit<IUserSettings, 'identifier' | 'level'>) {
|
||||
return await this.axios.patch('/api/user', u)
|
||||
}
|
||||
|
||||
async quiz_getMany(params: {
|
||||
async quiz_getMany(payload: {
|
||||
entries: string[]
|
||||
select: string[]
|
||||
type?: string
|
||||
direction?: string
|
||||
}) {
|
||||
return await this.axios.post('/api/quiz/getMany', params).then(
|
||||
return await this.axios.post('/api/quiz/getMany', payload).then(
|
||||
(r) =>
|
||||
r.data as {
|
||||
result: {
|
||||
@@ -123,6 +130,18 @@ class Api {
|
||||
)
|
||||
}
|
||||
|
||||
async quiz_getSrsLevel(payload: { entries: string[]; type: IType }) {
|
||||
return await this.axios.post('/api/quiz/getSrsLevel', payload).then(
|
||||
(r) =>
|
||||
r.data as {
|
||||
result: {
|
||||
entry: string
|
||||
srsLevel: number
|
||||
}[]
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async quiz_create(payload: { entries: string[]; type: IType }) {
|
||||
return await this.axios.put('/api/quiz', payload).then(
|
||||
(r) =>
|
||||
@@ -224,7 +243,9 @@ class Api {
|
||||
)
|
||||
}
|
||||
|
||||
async all_getLookup(params: ILookup<{ entry: string; type: IType }>) {
|
||||
async all_getLookup(
|
||||
params: ILookup<{ entry: string; type: IType; forced?: boolean }>
|
||||
) {
|
||||
params.offset = params.offset || 0
|
||||
params.limit = params.limit || 5
|
||||
|
||||
@@ -271,6 +292,12 @@ class Api {
|
||||
)
|
||||
}
|
||||
|
||||
async library_getQuery(params: ILookup<{ q: string }>) {
|
||||
return await this.axios
|
||||
.get('/api/library/q', { params })
|
||||
.then((r) => r.data as ILookupResult<ILibrary>)
|
||||
}
|
||||
|
||||
async library_getLevelList(payload: {
|
||||
type: ITypeLevel
|
||||
settings: ILevelBrowserByType
|
||||
@@ -285,6 +312,25 @@ class Api {
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async library_create(payload: Omit<ILibrary, 'id'>) {
|
||||
return await this.axios.put('/api/library', payload).then(
|
||||
(r) =>
|
||||
r.data as {
|
||||
id: string
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
async library_update(payload: ILibrary) {
|
||||
return await this.axios.patch('/api/library', payload, {
|
||||
params: { id: payload.id },
|
||||
})
|
||||
}
|
||||
|
||||
async library_delete(params: { id: string }) {
|
||||
return await this.axios.delete('/api/library', { params })
|
||||
}
|
||||
}
|
||||
|
||||
export const api = new Api()
|
||||
+3
-3
@@ -45,7 +45,7 @@ export const doMapKeypress = (
|
||||
export function shuffle<T>(a: T[]) {
|
||||
for (let i = a.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1))
|
||||
;[a[i], a[j]] = [a[j], a[i]]
|
||||
;[a[i], a[j]] = [a[j]!, a[i]!]
|
||||
}
|
||||
return a
|
||||
}
|
||||
@@ -60,7 +60,7 @@ export function sample<T>(arr: T[], size: number): T[] {
|
||||
outN.push(...allN.splice(Math.floor(Math.random() * allN.length), 1))
|
||||
}
|
||||
|
||||
return outN.map((n) => arr[n])
|
||||
return outN.map((n) => arr[n]!)
|
||||
}
|
||||
|
||||
export function capitalize(s: string): string {
|
||||
@@ -72,7 +72,7 @@ export function capitalize(s: string): string {
|
||||
}
|
||||
|
||||
if (!s) return s
|
||||
return s[0].toLocaleUpperCase() + s.substr(1)
|
||||
return s[0]!.toLocaleUpperCase() + s.substr(1)
|
||||
}
|
||||
|
||||
export function jsonClone<T>(o: T): T {
|
||||
|
||||
Reference in new issue
Block a user