Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Reset Button + homepage changes + view more #8

Merged
merged 9 commits into from
Oct 25, 2023
24 changes: 16 additions & 8 deletions src/TachiDesk/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const selectedSourcesSettings = async (stateManager: SourceStateManager,
labelResolver: async (option) => tachiSources.getAllSources()[option]["displayName"],
value: App.createDUIBinding({
async get() {
return await tachiSources.getSelectedSources(stateManager);
return (await tachiSources.getSelectedSources(stateManager));
},
async set(newValue) {
await tachiSources.setSelectedSources(stateManager, newValue)
Expand Down Expand Up @@ -124,17 +124,25 @@ export const selectedCategoriesSettings = async (stateManager: SourceStateManage

// Button that's supposed to reset all settings.
// Seems to be currently broken (8-1-23) [m/d/yyyy].
export const resetSettingsButton = (stateManager: SourceStateManager, tachiAPI: TachiAPIClass, tachiSources: TachiSourcesClass, tachiCategories: TachiCategoriesClass): DUIButton => {
export const resetSettingsButton = async (stateManager: SourceStateManager, tachiAPI: TachiAPIClass, tachiSources: TachiSourcesClass, tachiCategories: TachiCategoriesClass): Promise<DUIButton> => {
return App.createDUIButton({
id: "reset_button",
label: "Reset to Default",
onTap: async () => {
await Promise.all([
await tachiAPI.setServerAddress(stateManager, null),
await tachiSources.setSelectedSources(stateManager, null),
await tachiCategories.setSelectedCategories(stateManager, null),
await tachiSources.setAllSources(stateManager, null)
])
await tachiAPI.setServerAddress(stateManager, "http://127.0.0.1:4567")
await tachiSources.setSelectedSources(stateManager, ["0"])
await tachiCategories.setSelectedCategories(stateManager, ["0"])
await tachiSources.setAllSources(stateManager, {
"0": {
"name": "Local source",
"lang": "localsourcelang",
"iconUrl": "/api/v1/extension/icon/localSource",
"supportsLatest": true,
"isConfigurable": false,
"isNsfw": false,
"displayName": "Local source"
}
})
}
})
}
100 changes: 63 additions & 37 deletions src/TachiDesk/TachiDesk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ import {
serverAddressSettings
} from './Settings';

export const TachideskInfo: SourceInfo = {
export const TachiDeskInfo: SourceInfo = {
author: 'ofelizestevez & Alles',
description: 'Paperback extension which aims to bridge all of Tachidesks features and the Paperback App.',
icon: 'icon.png',
name: 'Tachidesk',
version: '1.0',
version: '1.1',
websiteBaseURL: "https://github.com/Suwayomi/Tachidesk-Server",
contentRating: ContentRating.EVERYONE,
sourceTags: [
Expand All @@ -48,7 +48,7 @@ export const TachideskInfo: SourceInfo = {
intents: SourceIntents.MANGA_CHAPTERS | SourceIntents.SETTINGS_UI | SourceIntents.HOMEPAGE_SECTIONS
}

export class Tachidesk implements HomePageSectionsProviding, ChapterProviding, SearchResultsProviding {
export class TachiDesk implements HomePageSectionsProviding, ChapterProviding, SearchResultsProviding {

// Paperback required defaults
// Statemanager saves states for the extension (like localstorage api)
Expand Down Expand Up @@ -81,7 +81,7 @@ export class Tachidesk implements HomePageSectionsProviding, ChapterProviding, S
serverAddressSettings(this.stateManager, this.requestManager, tachiAPI),
await selectedSourcesSettings(this.stateManager, this.requestManager, tachiAPI, this.tachiSources),
await selectedCategoriesSettings(this.stateManager, this.requestManager, tachiAPI, this.tachiCategories),
resetSettingsButton(this.stateManager, tachiAPI, this.tachiSources, this.tachiCategories),
await resetSettingsButton(this.stateManager, tachiAPI, this.tachiSources, this.tachiCategories),
]
})
}
Expand Down Expand Up @@ -169,15 +169,6 @@ export class Tachidesk implements HomePageSectionsProviding, ChapterProviding, S
const chapterResponse = await tachiAPI.makeRequest(this.requestManager, "/manga/" + mangaId + "/chapter/" + chapterId)
const pages: string[] = []

await tachiAPI.makeRequest(this.requestManager, "/manga/" + mangaId + "/chapter/" + chapterId, "PUT", {
"read": "true",
"bookmarked": "",
"markPrevRead": "",
"lastPageRead": ""
}, {
"Content-Type": "application/json",
})

for (const pageIndex of Array(chapterResponse.pageCount).keys()) {
pages.push(tachiAPI.getBaseURL() + "/manga/" + mangaId + "/chapter/" + chapterId + "/page/" + pageIndex)
}
Expand Down Expand Up @@ -205,7 +196,7 @@ export class Tachidesk implements HomePageSectionsProviding, ChapterProviding, S
id: "unset",
title: "Server Error",
containsMoreItems: false,
type: "singleRowNormal",
type: HomeSectionType.singleRowNormal,
items: serverUnavailableMangaTiles()
});
sectionCallback(section);
Expand All @@ -216,19 +207,20 @@ export class Tachidesk implements HomePageSectionsProviding, ChapterProviding, S
id: "unset",
title: "Server Error",
containsMoreItems: false,
type: "singleRowNormal",
type: HomeSectionType.singleRowNormal,
items: serverUnavailableMangaTiles()
});
sectionCallback(section);
return;
}

// Last test to ensure that we can connect to the server
if ((await this.tachiAPI).makeRequest(this.requestManager, "/settings/about") instanceof Error) {
const section = App.createHomeSection({
id: "unset",
title: "Server Error",
containsMoreItems: false,
type: "singleRowNormal",
type: HomeSectionType.singleRowNormal,
items: serverUnavailableMangaTiles()
});
sectionCallback(section);
Expand All @@ -241,7 +233,7 @@ export class Tachidesk implements HomePageSectionsProviding, ChapterProviding, S
id: "updated",
title: "Last Updated",
containsMoreItems: true,
type: HomeSectionType.featured
type: HomeSectionType.singleRowNormal
}),
request: App.createRequest({
url: tachiAPI.getBaseURL() + "/update/recentChapters/0",
Expand All @@ -256,9 +248,9 @@ export class Tachidesk implements HomePageSectionsProviding, ChapterProviding, S
sections.push({
section: App.createHomeSection({
id: "category-" + categoryId,
title: tachiCategories.getSelectedCategoryFromId(categoryId as string),
containsMoreItems: false,
type: HomeSectionType.singleRowLarge
title: tachiCategories.getSelectedCategoryFromId(categoryId.toString()),
containsMoreItems: true,
type: HomeSectionType.singleRowNormal
}),
request: App.createRequest({
url: tachiAPI.getBaseURL() + "/category/" + categoryId,
Expand Down Expand Up @@ -313,10 +305,10 @@ export class Tachidesk implements HomePageSectionsProviding, ChapterProviding, S
const tiles = []
if (section.type == "update") {

for (const manga of json.page) {
for (const manga of json.page.slice(0, 10)) {
tiles.push(
App.createPartialSourceManga({
title: manga.chapter.name,
title: manga.manga.title,
mangaId: manga.manga.id.toString(),
image: await tachiAPI.getServerAddress(this.stateManager) + manga.manga.thumbnailUrl,
subtitle: ""
Expand All @@ -325,9 +317,8 @@ export class Tachidesk implements HomePageSectionsProviding, ChapterProviding, S

}
}

if (section.type == "category") {
for (const manga of json) {
for (const manga of json.slice(0, 10)) {
tiles.push(
App.createPartialSourceManga({
title: manga.title,
Expand All @@ -338,7 +329,7 @@ export class Tachidesk implements HomePageSectionsProviding, ChapterProviding, S
}
}
if (section.type == "source") {
for (const manga of json.mangaList) {
for (const manga of json.mangaList.slice(0, 10)) {
tiles.push(
App.createPartialSourceManga({
title: manga.title,
Expand All @@ -351,7 +342,6 @@ export class Tachidesk implements HomePageSectionsProviding, ChapterProviding, S
}



section.section.items = tiles
sectionCallback(section.section)
})
Expand All @@ -364,7 +354,6 @@ export class Tachidesk implements HomePageSectionsProviding, ChapterProviding, S
// Handles when users click on the "more" button in the homepage.
// Currently only set up to work with sources
async getViewMoreItems(homepageSectionId: string, metadata: any): Promise<PagedResults> {
const page = metadata?.page ?? 1;
const sourceId = homepageSectionId.split('-').pop() ?? ""
const type = homepageSectionId.split("-")[0]
const tachiAPI = await this.tachiAPI
Expand All @@ -374,17 +363,54 @@ export class Tachidesk implements HomePageSectionsProviding, ChapterProviding, S
throw tachiSources;
}

const tileData = await tachiAPI.makeRequest(this.requestManager, "/source/" + sourceId + "/" + type + "/" + page)
const tiles = []

for (const tile of tileData.mangaList) {
tiles.push(
App.createPartialSourceManga({
mangaId: tile.id.toString(),
title: tile.title,
image: await tachiAPI.getServerAddress(this.stateManager) + tile.thumbnailUrl,
})
)
let tileData: any;
let page;

// Even if currentpageindex + 10 is bigger than currentpagelength, it will just cut to currentpagelength
switch (type) {
case "updated":
page = metadata?.page ?? 0;
tileData = await tachiAPI.makeRequest(this.requestManager, "/update/recentChapters/" + page)
for (const manga of tileData.page) {
tiles.push(
App.createPartialSourceManga({
title: manga.manga.title,
mangaId: manga.manga.id.toString(),
image: await tachiAPI.getServerAddress(this.stateManager) + manga.manga.thumbnailUrl,
subtitle: ""
})
)
}
break;
case "category":
page = metadata?.page ?? -1;
tileData = await tachiAPI.makeRequest(this.requestManager, "/category/" + sourceId)
for (const manga of tileData) {
tiles.push(
App.createPartialSourceManga({
title: manga.title,
mangaId: manga.id.toString(),
image: await tachiAPI.getServerAddress(this.stateManager) + manga.thumbnailUrl,
subtitle: ""
})
)
}
break
default:
page = metadata?.page ?? 1;
tileData = await tachiAPI.makeRequest(this.requestManager, "/source/" + sourceId + "/" + type + "/" + page)
for (const manga of tileData.mangaList) {
tiles.push(
App.createPartialSourceManga({
title: manga.title,
mangaId: manga.id.toString(),
image: await tachiAPI.getServerAddress(this.stateManager) + manga.thumbnailUrl,
subtitle: ""
})
)
}
break;
}

metadata = tileData.hasNextPage ? { page: page + 1 } : undefined
Expand Down
Loading