Extend interfaces and fix store userAnime store name

This commit is contained in:
Crow Crowcrow 2018-12-13 21:38:02 +01:00
parent 3a45726b3f
commit 6060dea8c4
Signed by: Crow
GPG Key ID: 45A8E203AF859FD8
2 changed files with 27 additions and 8 deletions

View File

@ -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()
},

View File

@ -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
}
}