Extend interfaces and fix store userAnime store name
This commit is contained in:
parent
3a45726b3f
commit
6060dea8c4
@ -3,36 +3,36 @@ import { RootState } from '@/store'
|
|||||||
import { BareActionContext, getStoreBuilder } from 'vuex-typex'
|
import { BareActionContext, getStoreBuilder } from 'vuex-typex'
|
||||||
|
|
||||||
export interface UserAnimeState {
|
export interface UserAnimeState {
|
||||||
anime: Meikan.UserAnime[]
|
userAnime: Meikan.UserAnime[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialState: UserAnimeState = {
|
const initialState: UserAnimeState = {
|
||||||
anime: [],
|
userAnime: [],
|
||||||
}
|
}
|
||||||
const builder = getStoreBuilder<RootState>().module('userAnime', initialState)
|
const builder = getStoreBuilder<RootState>().module('userAnime', initialState)
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
const getterUserAnime = builder.read(function anime(state: UserAnimeState) {
|
const getterUserAnime = builder.read(function anime(state: UserAnimeState) {
|
||||||
return state.anime
|
return state.userAnime
|
||||||
})
|
})
|
||||||
|
|
||||||
// Mutations
|
// Mutations
|
||||||
function setAnime(state: UserAnimeState, animeList: Meikan.UserAnime[]) {
|
function setAnime(state: UserAnimeState, animeList: Meikan.UserAnime[]) {
|
||||||
state.anime = animeList
|
state.userAnime = animeList
|
||||||
}
|
}
|
||||||
|
|
||||||
// Action
|
// Action
|
||||||
async function fetchUserAnime(context: BareActionContext<UserAnimeState, RootState>, user: Meikan.User) {
|
async function fetchUserAnime(context: BareActionContext<UserAnimeState, RootState>, user: Meikan.User) {
|
||||||
const list = await GetUserAnime(user.id)
|
const list = await GetUserAnime(user.id)
|
||||||
|
|
||||||
userAnime.setAnime(list)
|
userAnimeState.setAnime(list)
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetUserAnime(context: BareActionContext<UserAnimeState, RootState>) {
|
function resetUserAnime(context: BareActionContext<UserAnimeState, RootState>) {
|
||||||
userAnime.setAnime([])
|
userAnimeState.setAnime([])
|
||||||
}
|
}
|
||||||
|
|
||||||
export const userAnime = {
|
export const userAnimeState = {
|
||||||
get anime(): Meikan.UserAnime[] {
|
get anime(): Meikan.UserAnime[] {
|
||||||
return getterUserAnime()
|
return getterUserAnime()
|
||||||
},
|
},
|
||||||
|
21
src/types/shims-vue.d.ts
vendored
21
src/types/shims-vue.d.ts
vendored
@ -9,8 +9,27 @@ declare namespace Meikan {
|
|||||||
name: string
|
name: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UserAnime {
|
export interface Anime {
|
||||||
id: number
|
id: number
|
||||||
title: string
|
title: string
|
||||||
|
type: string
|
||||||
|
episodes: number
|
||||||
|
state: string
|
||||||
|
rating: string
|
||||||
|
start_date: string
|
||||||
|
end_date: string
|
||||||
|
genres: string[]
|
||||||
|
average_duration: number
|
||||||
|
anidb_id: number
|
||||||
|
myanimelist_id: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface UserAnime {
|
||||||
|
anime: Anime
|
||||||
|
state: string
|
||||||
|
episode: number
|
||||||
|
rating?: number
|
||||||
|
hidden: boolean
|
||||||
|
recommend: boolean
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user