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

View File

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