Skip to content

Commit

Permalink
Merge pull request #4 from TheNetsky/main
Browse files Browse the repository at this point in the history
Anilist | 1.1.1
  • Loading branch information
FaizanDurrani authored Mar 21, 2023
2 parents 59c656d + 93e4b3a commit 776c637
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
15 changes: 13 additions & 2 deletions src/Anilist/AlSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import {
SourceStateManager
} from '@paperback/types'

export const getdefaultStatus = async (stateManager: SourceStateManager): Promise<string[]> => {
export const getDefaultStatus = async (stateManager: SourceStateManager): Promise<string[]> => {
return (await stateManager.retrieve('defaultStatus') as string[]) ?? ['NONE']
}
export const getDefaultPrivate = async (stateManager: SourceStateManager): Promise<boolean> => {
return (await stateManager.retrieve('defaultPrivate') as boolean) ?? false
}

export const trackerSettings = (stateManager: SourceStateManager): DUINavigationButton => {
return App.createDUINavigationButton({
Expand All @@ -23,7 +26,7 @@ export const trackerSettings = (stateManager: SourceStateManager): DUINavigation
label: 'Default Status',
allowsMultiselect: false,
value: App.createDUIBinding({
get: () => getdefaultStatus(stateManager),
get: () => getDefaultStatus(stateManager),
set: async (newValue) => await stateManager.store('defaultStatus', newValue)
}),
labelResolver: async (value) => {
Expand All @@ -46,6 +49,14 @@ export const trackerSettings = (stateManager: SourceStateManager): DUINavigation
'PAUSED',
'REPEATING'
]
}),
App.createDUISwitch({
id: 'defaultPrivate',
label: 'Private by Default',
value: App.createDUIBinding({
get: () => getDefaultPrivate(stateManager),
set: async (newValue) => await stateManager.store('defaultPrivate', newValue)
}),
})
]
})
Expand Down
32 changes: 21 additions & 11 deletions src/Anilist/Anilist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import * as AnilistManga from './models/anilist-manga'
import { AnilistResult } from './models/anilist-result'

import {
getdefaultStatus,
getDefaultPrivate,
getDefaultStatus,
trackerSettings
} from './AlSettings'

Expand All @@ -42,7 +43,7 @@ export const AnilistInfo: SourceInfo = {
author: 'Faizan Durrani ♥ Netsky',
contentRating: ContentRating.EVERYONE,
icon: 'icon.png',
version: '1.1.0',
version: '1.1.1',
description: 'Anilist Tracker',
websiteBaseURL: 'https://anilist.co',
intents: SourceIntents.MANGA_TRACKING | SourceIntents.SETTINGS_UI
Expand Down Expand Up @@ -267,7 +268,7 @@ export class Anilist implements Searchable, MangaProgressProviding {
App.createDUISelect({
id: 'status',
//@ts-ignore
value: anilistManga.mediaListEntry?.status ? [anilistManga.mediaListEntry.status] : (await getdefaultStatus(this.stateManager)),
value: anilistManga.mediaListEntry?.status ? [anilistManga.mediaListEntry.status] : (await getDefaultStatus(this.stateManager)),
allowsMultiselect: false,
label: 'Status',
labelResolver: async (value) => {
Expand Down Expand Up @@ -327,6 +328,20 @@ export class Anilist implements Searchable, MangaProgressProviding {
})
]
}),
// Private
App.createDUISection({
id: 'mangaPrivate',
header: 'Private',
isHidden: false,
rows: async () => [
App.createDUISwitch({
id: 'private',
label: 'Private',
//@ts-ignore
value: anilistManga.mediaListEntry?.private ? [anilistManga.mediaListEntry.private] : (await getDefaultPrivate(this.stateManager))
})
]
}),
// Notes
App.createDUISection({
id: 'mangaNotes',
Expand All @@ -345,27 +360,22 @@ export class Anilist implements Searchable, MangaProgressProviding {
},
onSubmit: async (values) => {

console.log(JSON.stringify(values, null, 2)) // Log new values

let mutation: GraphQLQuery
const status = values['status']?.[0] ?? ''
const id = Number(tempData.id) //values['id'] != null ? Number(values['id']) : undefined
const id = tempData.id ? Number(tempData.id) : undefined //values['id'] != null ? Number(values['id']) : undefined
const mediaId = Number(tempData.mediaId) //Number(values['mediaId'])

if (isNaN(id) || isNaN(mediaId)) { // If either the "tracking id" or "mediaId" (mangaId) is missing, abort the request!
throw new Error(`Either id (${id}) or mediaId (${mediaId}) is NaN!`)
}

if (status == 'NONE' && id != null) {
mutation = deleteMangaProgressMutation(id)
} else {
mutation = saveMangaProgressMutation({
id: id,
mediaId: mangaId,
mediaId: mediaId,
status: status,
notes: values['notes'],
progress: values['progress'],
progressVolumes: values['progressVolumes'],
private: values['private'],
score: Number(values['score'])
})
}
Expand Down
5 changes: 3 additions & 2 deletions src/Anilist/models/graphql-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,15 @@ export interface SaveMangaProgressVariables {
mediaId?: number | string;
status?: string;
score?: number;
private?: boolean;
progress?: number;
progressVolumes?: number;
notes?: string;
}

export const saveMangaProgressMutation = (variables: SaveMangaProgressVariables): GraphQLQuery => ({
query: `mutation($id: Int, $mediaId: Int, $status: MediaListStatus, $score: Float, $progress: Int, $progressVolumes: Int, $notes: String) {
SaveMediaListEntry(id: $id, mediaId: $mediaId, status: $status, score: $score, progress: $progress, progressVolumes: $progressVolumes, notes: $notes){
query: `mutation($id: Int, $mediaId: Int, $status: MediaListStatus, $score: Float, $progress: Int, $progressVolumes: Int, $notes: String, $private: Boolean) {
SaveMediaListEntry(id: $id, mediaId: $mediaId, status: $status, score: $score, progress: $progress, progressVolumes: $progressVolumes, notes: $notes, private: $private){
id
}
}`,
Expand Down

0 comments on commit 776c637

Please sign in to comment.