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'
|
||||
|
||||
export interface UserAnimeState {
|
||||
anime: Meikan.UserAnime[]
|
||||
userAnime: Meikan.UserAnime[]
|
||||
}
|
||||
|
||||
const initialState: UserAnimeState = {
|
||||
anime: [],
|
||||
userAnime: [],
|
||||
}
|
||||
const builder = getStoreBuilder<RootState>().module('userAnime', initialState)
|
||||
|
||||
// Getters
|
||||
const getterUserAnime = builder.read(function anime(state: UserAnimeState) {
|
||||
return state.anime
|
||||
return state.userAnime
|
||||
})
|
||||
|
||||
// Mutations
|
||||
function setAnime(state: UserAnimeState, animeList: Meikan.UserAnime[]) {
|
||||
state.anime = animeList
|
||||
state.userAnime = animeList
|
||||
}
|
||||
|
||||
// Action
|
||||
async function fetchUserAnime(context: BareActionContext<UserAnimeState, RootState>, user: Meikan.User) {
|
||||
const list = await GetUserAnime(user.id)
|
||||
|
||||
userAnime.setAnime(list)
|
||||
userAnimeState.setAnime(list)
|
||||
}
|
||||
|
||||
function resetUserAnime(context: BareActionContext<UserAnimeState, RootState>) {
|
||||
userAnime.setAnime([])
|
||||
userAnimeState.setAnime([])
|
||||
}
|
||||
|
||||
export const userAnime = {
|
||||
export const userAnimeState = {
|
||||
get anime(): Meikan.UserAnime[] {
|
||||
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
|
||||
}
|
||||
|
||||
export interface UserAnime {
|
||||
export interface Anime {
|
||||
id: number
|
||||
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