frontend: fix typing issues
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
import {Options, Vue} from 'vue-class-component';
|
import {Options, Vue} from 'vue-class-component';
|
||||||
import {Prop, Watch} from 'vue-property-decorator';
|
import {Prop, Watch} from 'vue-property-decorator';
|
||||||
import {BTable, type TableItem} from 'bootstrap-vue-next';
|
import {BTable, type TableItem} from 'bootstrap-vue-next';
|
||||||
|
//@ts-ignore TS2307
|
||||||
import type {TableFieldObject} from 'bootstrap-vue-next/dist/src/types';
|
import type {TableFieldObject} from 'bootstrap-vue-next/dist/src/types';
|
||||||
import type {ViewEntry, ViewList} from '@/components/manga/MangaList.vue';
|
import type {ViewEntry, ViewList} from '@/components/manga/MangaList.vue';
|
||||||
import MangaEntryDetailsModal from '@/components/manga/MangaEntryDetailsModal.vue';
|
import MangaEntryDetailsModal from '@/components/manga/MangaEntryDetailsModal.vue';
|
||||||
@@ -110,7 +111,7 @@ export default class MangaListTable extends Vue {
|
|||||||
<div>
|
<div>
|
||||||
<BTable ref="table" v-if="bTableRefreshHack" :fields="fields" :items="tableEntries" :primary-key="'id'"
|
<BTable ref="table" v-if="bTableRefreshHack" :fields="fields" :items="tableEntries" :primary-key="'id'"
|
||||||
class="manga-table" hover striped responsive no-sort-reset sort-by="newChapters" sort-desc
|
class="manga-table" hover striped responsive no-sort-reset sort-by="newChapters" sort-desc
|
||||||
@row-clicked="onRowClicked">
|
@row-clicked="onRowClicked as any /* TODO dumb typing issue */">
|
||||||
<template #cell(media.coverImage.large)="data">
|
<template #cell(media.coverImage.large)="data">
|
||||||
<img :src="data.value as string" alt="cover-img" class="list-cover"/>
|
<img :src="data.value as string" alt="cover-img" class="list-cover"/>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import type {AniListMedia} from '@/data/models/anilist/AniListMedia';
|
|||||||
import type {MangaUpdatesRelation} from '@/data/models/mangaupdates/MangaUpdatesRelation';
|
import type {MangaUpdatesRelation} from '@/data/models/mangaupdates/MangaUpdatesRelation';
|
||||||
import type {MangaUpdatesSeries} from '@/data/models/mangaupdates/MangaUpdatesSeries';
|
import type {MangaUpdatesSeries} from '@/data/models/mangaupdates/MangaUpdatesSeries';
|
||||||
import type {MangaUpdatesChapter} from '@/data/models/mangaupdates/MangaUpdatesChapter';
|
import type {MangaUpdatesChapter} from '@/data/models/mangaupdates/MangaUpdatesChapter';
|
||||||
|
import groupBy from '@/util';
|
||||||
|
|
||||||
@Options({
|
@Options({
|
||||||
name: 'MangaLists',
|
name: 'MangaLists',
|
||||||
@@ -34,7 +35,7 @@ export default class MangaLists extends Vue {
|
|||||||
|
|
||||||
get chaptersBySeriesId(): Map<number, MangaUpdatesChapter[]> {
|
get chaptersBySeriesId(): Map<number, MangaUpdatesChapter[]> {
|
||||||
const chapters = this.mangaStore.mangaUpdatesChapters;
|
const chapters = this.mangaStore.mangaUpdatesChapters;
|
||||||
return Map.groupBy(chapters, e => e.series_id);
|
return groupBy(chapters, e => e.series_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
get viewLists(): ViewList[] {
|
get viewLists(): ViewList[] {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export default class AniListApi {
|
|||||||
'variables': {'name': userName},
|
'variables': {'name': userName},
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
return (await handleJsonResponse(res)).data.User;
|
return ((await handleJsonResponse(res)) as any).data.User;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchManga(userId: number): Promise<AniListMangaListCollection> {
|
async fetchManga(userId: number): Promise<AniListMangaListCollection> {
|
||||||
@@ -28,6 +28,6 @@ export default class AniListApi {
|
|||||||
'variables': {'userId': userId, 'type': 'MANGA'},
|
'variables': {'userId': userId, 'type': 'MANGA'},
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
return (await handleJsonResponse(res)).data.MediaListCollection;
|
return ((await handleJsonResponse(res)) as any).data.MediaListCollection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import {type IDBPDatabase, openDB} from 'idb';
|
import {type IDBPDatabase, openDB} from 'idb';
|
||||||
import type {MangaUpdatesSeries} from '@/data/models/mangaupdates/MangaUpdatesSeries';
|
import type {MangaUpdatesSeries} from '@/data/models/mangaupdates/MangaUpdatesSeries';
|
||||||
import type {MangaUpdatesChapter} from '@/data/models/mangaupdates/MangaUpdatesChapter';
|
import type {MangaUpdatesChapter} from '@/data/models/mangaupdates/MangaUpdatesChapter';
|
||||||
|
import type {MangaUpdatesRelation} from '@/data/models/mangaupdates/MangaUpdatesRelation';
|
||||||
|
|
||||||
export type MuDb = IDBPDatabase<MangaUpdatesDBSchema>;
|
export type MuDb = IDBPDatabase<MangaUpdatesDBSchema>;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import MangaUpdatesDb from '@/data/db/MangaUpdatesDb';
|
import MangaUpdatesDb from '@/data/db/MangaUpdatesDb';
|
||||||
import type {MangaUpdatesRelation} from '@/data/models/mangaupdates/MangaUpdatesRelation';
|
import type {MangaUpdatesRelation} from '@/data/models/mangaupdates/MangaUpdatesRelation';
|
||||||
import type {MangaUpdatesMedia} from '@/data/models/mangaupdates/MangaUpdatesMedia';
|
|
||||||
import type {MangaUpdatesChapter} from '@/data/models/mangaupdates/MangaUpdatesChapter';
|
import type {MangaUpdatesChapter} from '@/data/models/mangaupdates/MangaUpdatesChapter';
|
||||||
import type {MangaUpdatesSeries} from '@/data/models/mangaupdates/MangaUpdatesSeries';
|
import type {MangaUpdatesSeries} from '@/data/models/mangaupdates/MangaUpdatesSeries';
|
||||||
|
|
||||||
@@ -25,7 +24,7 @@ export default class MangaUpdatesRepository {
|
|||||||
|
|
||||||
async getSeriesById(id: number) {
|
async getSeriesById(id: number) {
|
||||||
return await MangaUpdatesDb.withDb(async db => {
|
return await MangaUpdatesDb.withDb(async db => {
|
||||||
return await db.get('series', id);
|
return await db.get('series', IDBKeyRange.only(id));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +52,7 @@ export default class MangaUpdatesRepository {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateSeries(newSeries: MangaUpdatesMedia[]) {
|
async updateSeries(newSeries: MangaUpdatesSeries[]) {
|
||||||
return await MangaUpdatesDb.withDb(async db => {
|
return await MangaUpdatesDb.withDb(async db => {
|
||||||
let txList = db.transaction('series', 'readwrite');
|
let txList = db.transaction('series', 'readwrite');
|
||||||
await Promise.allSettled([
|
await Promise.allSettled([
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import type {MangaUpdatesChapter} from '@/data/models/mangaupdates/MangaUpdatesC
|
|||||||
import type {MangaUpdatesSearchResultRecord} from '@/data/models/mangaupdates/MangaUpdatesSearchResultRecord';
|
import type {MangaUpdatesSearchResultRecord} from '@/data/models/mangaupdates/MangaUpdatesSearchResultRecord';
|
||||||
import stringSimilarity from 'string-similarity-js';
|
import stringSimilarity from 'string-similarity-js';
|
||||||
import {ApiError} from '@/data/api/ApiUtils';
|
import {ApiError} from '@/data/api/ApiUtils';
|
||||||
|
import groupBy from '@/util';
|
||||||
|
|
||||||
export default class MangaUpdatesDataService {
|
export default class MangaUpdatesDataService {
|
||||||
private readonly mangaUpdatesApi = new MangaUpdatesApi();
|
private readonly mangaUpdatesApi = new MangaUpdatesApi();
|
||||||
@@ -63,7 +64,8 @@ export default class MangaUpdatesDataService {
|
|||||||
matching = results.results
|
matching = results.results
|
||||||
.filter(e => stringSimilarity(title, e.record.title, 2, false) >= 0.95)
|
.filter(e => stringSimilarity(title, e.record.title, 2, false) >= 0.95)
|
||||||
.filter(e => allowTypes.has(e.record.type.toLowerCase())) //check if a manga or similar but not novel
|
.filter(e => allowTypes.has(e.record.type.toLowerCase())) //check if a manga or similar but not novel
|
||||||
.filter(e => m.startDate.year - 1 <= e.record.year && e.record.year <= m.startDate.year + 1); //check year +-1
|
.filter(e => m.startDate.year - 1 <= parseInt('' + e.record.year)
|
||||||
|
&& parseInt('' + e.record.year) <= m.startDate.year + 1); //check year +-1
|
||||||
if (matching.length === 0) {
|
if (matching.length === 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -148,7 +150,7 @@ export default class MangaUpdatesDataService {
|
|||||||
.flat();
|
.flat();
|
||||||
|
|
||||||
//only keep chapter with the highest chapter number per group
|
//only keep chapter with the highest chapter number per group
|
||||||
const filtered = Array.from(Map.groupBy(updates, c => c.group).values())
|
const filtered = Array.from(groupBy(updates, c => c.group).values())
|
||||||
.map(chaptersOfGroup => chaptersOfGroup.reduce((l, r) => l.chapter > r.chapter ? l : r, chaptersOfGroup[0]));
|
.map(chaptersOfGroup => chaptersOfGroup.reduce((l, r) => l.chapter > r.chapter ? l : r, chaptersOfGroup[0]));
|
||||||
await mangaStore.updateMangaUpdatesChapters(filtered);
|
await mangaStore.updateMangaUpdatesChapters(filtered);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export function createI18n(): I18n {
|
|||||||
locale: browserLocale,
|
locale: browserLocale,
|
||||||
fallbackLocale: 'en',
|
fallbackLocale: 'en',
|
||||||
messages: messages,
|
messages: messages,
|
||||||
|
//@ts-ignore TS2769 TODO weird typing issue
|
||||||
datetimeFormats: datetimeFormats,
|
datetimeFormats: datetimeFormats,
|
||||||
legacy: true,
|
legacy: true,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
/// reference <../types/polyfill.d.ts>
|
|
||||||
|
|
||||||
import groupBy from '@/util';
|
|
||||||
|
|
||||||
Map.groupBy = groupBy;
|
|
||||||
@@ -7,6 +7,7 @@ import type {AniListMangaList} from '@/data/models/anilist/AniListMangaList';
|
|||||||
import type {MangaUpdatesRelation} from '@/data/models/mangaupdates/MangaUpdatesRelation';
|
import type {MangaUpdatesRelation} from '@/data/models/mangaupdates/MangaUpdatesRelation';
|
||||||
import type {MangaUpdatesChapter} from '@/data/models/mangaupdates/MangaUpdatesChapter';
|
import type {MangaUpdatesChapter} from '@/data/models/mangaupdates/MangaUpdatesChapter';
|
||||||
import type {MangaUpdatesSeries} from '@/data/models/mangaupdates/MangaUpdatesSeries';
|
import type {MangaUpdatesSeries} from '@/data/models/mangaupdates/MangaUpdatesSeries';
|
||||||
|
import groupBy from '@/util';
|
||||||
|
|
||||||
@Store({
|
@Store({
|
||||||
id: 'MangaStore',
|
id: 'MangaStore',
|
||||||
@@ -100,8 +101,8 @@ export class MangaStore extends Pinia {
|
|||||||
await this.dbStore.mangaUpdatesRepository.updateChapters(chapters);
|
await this.dbStore.mangaUpdatesRepository.updateChapters(chapters);
|
||||||
|
|
||||||
// update cache
|
// update cache
|
||||||
const cachedById = Map.groupBy(this.cachedMangaUpdatesChapters, c => c.series_id);
|
const cachedById = groupBy(this.cachedMangaUpdatesChapters, c => c.series_id);
|
||||||
const chaptersById = Map.groupBy(chapters, c => c.series_id);
|
const chaptersById = groupBy(chapters, c => c.series_id);
|
||||||
chaptersById.forEach((v, k) => cachedById.set(k, v));
|
chaptersById.forEach((v, k) => cachedById.set(k, v));
|
||||||
this.cachedMangaUpdatesChapters.splice(0);
|
this.cachedMangaUpdatesChapters.splice(0);
|
||||||
this.cachedMangaUpdatesChapters.push(...Array.from(cachedById.values()).flat());
|
this.cachedMangaUpdatesChapters.push(...Array.from(cachedById.values()).flat());
|
||||||
|
|||||||
3
frontend/types/polyfill.d.ts
vendored
3
frontend/types/polyfill.d.ts
vendored
@@ -1,3 +0,0 @@
|
|||||||
declare interface MapConstructor {
|
|
||||||
groupBy<K, V>(arr: V[], fn: (v: V) => K): Map<K, V[]>;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user