Skip to content

Commit 086e0e1

Browse files
committed
Type adjustments.
1 parent 723c10d commit 086e0e1

File tree

4 files changed

+35
-19
lines changed

4 files changed

+35
-19
lines changed

frontend/src/api/discogs.ts

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { isNullOrBlank } from "../utils"
2-
import { ICollections, IIdentify, IProfile, IReleases, IReleaseSet, VinylAPIImageMap } from "./interface"
2+
import {
3+
ICollections,
4+
IIdentify,
5+
IProfile,
6+
IReleases,
7+
IReleaseSet,
8+
VinylAPIImageMap,
9+
VinylAPIImageRecord,
10+
} from "./interface"
311

412
const API_URL = "https://api.discogs.com"
513

@@ -36,11 +44,8 @@ export const getCollectionAndWants = async (
3644
onProgress?: (page: number, pages: number) => void
3745
): Promise<IReleaseSet> => {
3846
const vinylURL = import.meta.env.VITE_VINYL_API_URL
39-
40-
const fetchReleases = async (
41-
url: string,
42-
releaseType: 'collection' | 'wants'
43-
): Promise<IReleases[]> => {
47+
48+
const fetchReleases = async (url: string, releaseType: "collection" | "wants"): Promise<IReleases[]> => {
4449
let allReleases: IReleases[] = []
4550
while (url) {
4651
const response = await fetch(url, {
@@ -66,21 +71,27 @@ export const getCollectionAndWants = async (
6671
},
6772
body: JSON.stringify(
6873
// @ts-expect-error Cheating a bit - converting the reference to keep the same models.
69-
(releaseType === 'wants' ? data.wants : data.releases).map((item) => item.basic_information.id) ?? []
74+
(releaseType === "wants" ? data.wants : data.releases).map(
75+
// @ts-expect-error Cheating a bit - converting the reference to keep the same models.
76+
(item) => item.basic_information.id
77+
) ?? []
7078
),
7179
})
7280

7381
if (secondaryResponse.ok) {
7482
const imageData = await secondaryResponse.json()
7583

76-
imageMap = imageData.available.reduce((acc: Record<number, VinylAPIImageMap>, record: any) => {
77-
acc[record.recordID] = {
78-
image: record.image,
79-
imageHigh: record.imageHigh,
80-
barcode: record.barcode.replace(/\D/g, '') ?? undefined,
81-
}
82-
return acc
83-
}, {})
84+
imageMap = imageData.available.reduce(
85+
(acc: Record<number, VinylAPIImageMap>, record: VinylAPIImageRecord) => {
86+
acc[record.recordID] = {
87+
image: record.image,
88+
imageHigh: record.imageHigh,
89+
barcode: record.barcode?.replace(/\D/g, "") ?? undefined,
90+
}
91+
return acc
92+
},
93+
{}
94+
)
8495
} else {
8596
console.warn("Vinyl API response was not ok, skipping.")
8697
}
@@ -90,7 +101,7 @@ export const getCollectionAndWants = async (
90101
}
91102

92103
// @ts-expect-error Cheating a bit - converting the reference to keep the same models.
93-
const releasesExtraData = (releaseType === 'wants' ? data.wants : data.releases).map((release) => {
104+
const releasesExtraData = (releaseType === "wants" ? data.wants : data.releases).map((release) => {
94105
const imageRecord = imageMap[release.basic_information.id] || {
95106
image: null,
96107
imageHigh: null,
@@ -122,8 +133,8 @@ export const getCollectionAndWants = async (
122133

123134
// Fetch wants and collection in parallel
124135
const [wantsReleases, collectionReleases] = await Promise.all([
125-
fetchReleases(`${API_URL}/users/${username}/wants?per_page=100`, 'wants'),
126-
fetchReleases(`${API_URL}/users/${username}/collection/folders/0/releases?per_page=100`, 'collection'),
136+
fetchReleases(`${API_URL}/users/${username}/wants?per_page=100`, "wants"),
137+
fetchReleases(`${API_URL}/users/${username}/collection/folders/0/releases?per_page=100`, "collection"),
127138
])
128139

129140
return {

frontend/src/api/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ export type {
1010
IVinylResponse,
1111
IAvailableItem,
1212
VinylAPIImageMap,
13+
VinylAPIImageRecord,
1314
} from "./interface"

frontend/src/api/interface.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,7 @@ export interface VinylAPIImageMap {
126126
imageHigh?: string
127127
barcode?: string
128128
}
129+
130+
export interface VinylAPIImageRecord extends VinylAPIImageMap {
131+
recordID: number
132+
}

frontend/src/modal/Settings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const Settings: React.FC<Props> = ({ open, hasUpdate, onClose, onSave }) => {
7272

7373
const collection = queryClient.getQueryData<IReleaseSet>([`${username}collectionv2`])
7474
const collectionMissing = collection?.collection.filter((obj) => obj.image_base64 === undefined).length ?? 0
75-
const wantedMissing = collection?.wants.filter((obj) => obj.image_base64 === undefined).length ?? 0
75+
const wantedMissing = collection?.wants.filter((obj) => obj.image_base64 === undefined).length ?? 0
7676

7777
const inStorageInfo = {
7878
collectionCount: collection?.collection.length ?? 0,

0 commit comments

Comments
 (0)