added Not Reviewed so zero does not equal undefined

This commit is contained in:
John O'Keefe 2024-07-27 21:18:03 -04:00
parent ada4832904
commit 065ac0950f
8 changed files with 47 additions and 21 deletions

View File

@ -35,16 +35,38 @@ func AniListQuery(body interface{}, login bool) (json.RawMessage, string) {
return returnedBody, ""
}
func (a *App) GetAniListItem(aniId int) AniListGetSingleAnime {
func (a *App) GetAniListItem(aniId int, login bool) AniListGetSingleAnime {
var user = a.GetAniListLoggedInUserId()
type Variables struct {
UserId int `json:"userId"`
MediaId int `json:"mediaId"`
ListType string `json:"listType"`
// type Variables struct {
// UserId int `json:"userId"`
// MediaId int `json:"mediaId"`
// ListType string `json:"listType"`
// }
var neededVariables interface{}
if login {
neededVariables = struct{
MediaId int `json:"mediaId"`
UserId int `json:"userId"`
ListType string `json:"listType"`
} {
MediaId: aniId,
UserId: user.Data.Viewer.ID,
ListType: "ANIME",
}
} else {
neededVariables = struct {
MediaId int `json:"mediaId"`
ListType string `json:"listType"`
} {
MediaId: aniId,
ListType: "ANIME",
}
}
body := struct {
Query string `json:"query"`
Variables Variables `json:"variables"`
Variables interface{} `json:"variables"`
}{
Query: `
query($userId: Int, $mediaId: Int, $listType: MediaType) {
@ -109,15 +131,11 @@ func (a *App) GetAniListItem(aniId int) AniListGetSingleAnime {
}
}
`,
Variables: Variables{
MediaId: aniId,
UserId: user.Data.Viewer.ID,
ListType: "ANIME",
},
Variables: neededVariables,
}
returnedBody, _ := AniListQuery(body, false)
var post AniListGetSingleAnime
err := json.Unmarshal(returnedBody, &post)
if err != nil {

View File

@ -24,8 +24,9 @@
"vite": "^3.0.7"
},
"dependencies": {
"@ernane/svelte-star-rating": "^1.1.7",
"@popperjs/core": "^2.11.8",
"flowbite": "^2.4.1",
"flowbite-svelte": "^0.46.15",
"@popperjs/core": "^2.11.8"
"flowbite-svelte": "^0.46.15"
}
}

View File

@ -4,6 +4,7 @@
import StarRatting from "@ernane/svelte-star-rating"
const ratingInWords = {
0: "Not Reviewed",
1: "Apalling",
2: "Horrible",
3: "Very Bad",

View File

@ -7,8 +7,8 @@
export let title = writable("")
export let anilistModal = writable(false);
export function GetAniListSingleItemAndOpenModal(aniId: number): void {
GetAniListItem(aniId).then(result => {
export function GetAniListSingleItemAndOpenModal(aniId: number, login: boolean): void {
GetAniListItem(aniId, login).then(result => {
anime = result
title.set(anime.data.MediaList.media.title.english === "" ?
anime.data.MediaList.media.title.romaji :

View File

@ -10,7 +10,7 @@
function runAniListSearch(): void {
AniListSearch(aniSearch).then(result => {
console.log(result)
console.log(result.data.Page.media[5])
aniListSearch = result
aniListSearchActive = true
})
@ -52,7 +52,7 @@
{#each aniListSearch.data.Page.media as media}
<li class="w-full">
<button on:click={() => {
GetAniListSingleItemAndOpenModal(media.id)
GetAniListSingleItemAndOpenModal(media.id, false)
}}
class="flex w-full items-start p-1 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white rounded-lg">
<img class="rounded-bl-lg rounded-tl-lg max-w-24 max-h-24" src={media.coverImage.large}

View File

@ -8,7 +8,7 @@ export function AniListSearch(arg1:string):Promise<any>;
export function AniListUpdateEntry(arg1:number,arg2:string,arg3:string,arg4:number,arg5:number,arg6:string,arg7:number,arg8:number,arg9:number,arg10:number,arg11:number,arg12:number):Promise<any>;
export function GetAniListItem(arg1:number):Promise<main.AniListGetSingleAnime>;
export function GetAniListItem(arg1:number,arg2:boolean):Promise<main.AniListGetSingleAnime>;
export function GetAniListLoggedInUserId():Promise<main.AniListUser>;

View File

@ -14,8 +14,8 @@ export function AniListUpdateEntry(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg
return window['go']['main']['App']['AniListUpdateEntry'](arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12);
}
export function GetAniListItem(arg1) {
return window['go']['main']['App']['GetAniListItem'](arg1);
export function GetAniListItem(arg1, arg2) {
return window['go']['main']['App']['GetAniListItem'](arg1, arg2);
}
export function GetAniListLoggedInUserId() {

View File

@ -98,6 +98,10 @@ export namespace main {
// Go type: struct { ID int "json:\"id\""; IDMal int "json:\"idMal\""; Title struct { Romaji string "json:\"romaji\""; English string "json:\"english\""; Native string "json:\"native\"" } "json:\"title\""; Description string "json:\"description\""; CoverImage struct { Large string "json:\"large\"" } "json:\"coverImage\""; Season string "json:\"season\""; SeasonYear int "json:\"seasonYear\""; Status string "json:\"status\""; Episodes int "json:\"episodes\""; NextAiringEpisode struct { AiringAt int "json:\"airingAt\""; TimeUntilAiring int "json:\"timeUntilAiring\""; Episode int "json:\"episode\"" } "json:\"nextAiringEpisode\"" }
media: any;
status: string;
// Go type: struct { Year int "json:\"year\""; Month int "json:\"month\""; Day int "json:\"day\"" }
startedAt: any;
// Go type: struct { Year int "json:\"year\""; Month int "json:\"month\""; Day int "json:\"day\"" }
completedAt: any;
notes: string;
progress: number;
score: number;
@ -116,6 +120,8 @@ export namespace main {
this.userId = source["userId"];
this.media = this.convertValues(source["media"], Object);
this.status = source["status"];
this.startedAt = this.convertValues(source["startedAt"], Object);
this.completedAt = this.convertValues(source["completedAt"], Object);
this.notes = source["notes"];
this.progress = source["progress"];
this.score = source["score"];