update to new content tracker endpoints
This commit is contained in:
@@ -1,37 +1,21 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import ProjectComponent from '../ProjectComponent';
|
import ProjectComponent from '../ProjectComponent';
|
||||||
|
import type { ContentTrackerItem } from '../../utils/types';
|
||||||
type BookDataResponse = {
|
|
||||||
status: number,
|
|
||||||
data: BookData
|
|
||||||
};
|
|
||||||
type BookData = {
|
|
||||||
id: number,
|
|
||||||
title: string,
|
|
||||||
author: string,
|
|
||||||
description: string,
|
|
||||||
imageKey: string,
|
|
||||||
finished: boolean,
|
|
||||||
startedOn: Date,
|
|
||||||
createdAt: Date,
|
|
||||||
updatedAt: Date,
|
|
||||||
createdById: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function RecentBook() {
|
export default function RecentBook() {
|
||||||
const [ data, setData ] = useState<BookData | null>(null);
|
const [ data, setData ] = useState<ContentTrackerItem | null>(null);
|
||||||
const [ loading, setLoading ] = useState<boolean>(true);
|
const [ loading, setLoading ] = useState<boolean>(true);
|
||||||
const [ errorState, setErrorState ] = useState<string>("");
|
const [ errorState, setErrorState ] = useState<string>("");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch("https://api.alexav.gg/v4/social/books", {
|
fetch("https://api.alexav.gg/v4/tracker/latest/book", {
|
||||||
method: 'get'
|
method: 'get'
|
||||||
})
|
})
|
||||||
.then(async (res) => {
|
.then(async (res) => {
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const json = await res.json() as BookDataResponse;
|
const json = await res.json();
|
||||||
setData(json.data);
|
setData(json.data);
|
||||||
setLoading(false)
|
setLoading(false);
|
||||||
} else {
|
} else {
|
||||||
setErrorState("Failed to fetch data!");
|
setErrorState("Failed to fetch data!");
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@@ -61,7 +45,7 @@ export default function RecentBook() {
|
|||||||
projectHeader={data.title}
|
projectHeader={data.title}
|
||||||
projectSubheader={getDateString(data.startedOn, data.finished)}
|
projectSubheader={getDateString(data.startedOn, data.finished)}
|
||||||
url={"https://tracker.alexav.gg/?type=books&id=" + data.id}
|
url={"https://tracker.alexav.gg/?type=books&id=" + data.id}
|
||||||
projectImage={data.imageKey}
|
projectImage={data.image}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,19 +1,16 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import ProjectComponent from '../ProjectComponent';
|
import ProjectComponent from '../ProjectComponent';
|
||||||
|
|
||||||
type WatchDataResponse = {
|
|
||||||
status: number,
|
|
||||||
data: WatchData
|
|
||||||
};
|
|
||||||
type WatchData = {
|
type WatchData = {
|
||||||
id: number,
|
id: number,
|
||||||
title: string,
|
title: string,
|
||||||
description: string,
|
description: string,
|
||||||
imageKey: string,
|
author?: string,
|
||||||
currentEpisode: string,
|
image: string,
|
||||||
tmdbID: string,
|
episode?: string,
|
||||||
|
tmdbId?: string,
|
||||||
finished: boolean,
|
finished: boolean,
|
||||||
startedOn: Date,
|
startedOn?: Date,
|
||||||
createdAt: Date,
|
createdAt: Date,
|
||||||
updatedAt: Date,
|
updatedAt: Date,
|
||||||
createdById: string
|
createdById: string
|
||||||
@@ -25,12 +22,12 @@ export default function RecentWatch() {
|
|||||||
const [ errorState, setErrorState ] = useState<string>("");
|
const [ errorState, setErrorState ] = useState<string>("");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch("https://api.alexav.gg/v4/social/watch", {
|
fetch("https://api.alexav.gg/v4/tracker/latest/tv", {
|
||||||
method: 'get'
|
method: 'get'
|
||||||
})
|
})
|
||||||
.then(async (res) => {
|
.then(async (res) => {
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const json = await res.json() as WatchDataResponse;
|
const json = await res.json();
|
||||||
setData(json.data);
|
setData(json.data);
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
} else {
|
} else {
|
||||||
@@ -48,7 +45,7 @@ export default function RecentWatch() {
|
|||||||
if (data?.finished) {
|
if (data?.finished) {
|
||||||
return "Finished!"
|
return "Finished!"
|
||||||
} else if (data?.startedOn) {
|
} else if (data?.startedOn) {
|
||||||
return "Started on " + new Date(data.startedOn).toLocaleDateString()
|
return "Last update on " + new Date(data.updatedAt).toLocaleDateString()
|
||||||
} else {
|
} else {
|
||||||
return "Just Added"
|
return "Just Added"
|
||||||
}
|
}
|
||||||
@@ -61,7 +58,7 @@ export default function RecentWatch() {
|
|||||||
projectHeader={data.title}
|
projectHeader={data.title}
|
||||||
projectSubheader={ getSubheaderText() }
|
projectSubheader={ getSubheaderText() }
|
||||||
url={"https://tracker.alexav.gg/?type=tv&id=" + data.id}
|
url={"https://tracker.alexav.gg/?type=tv&id=" + data.id}
|
||||||
projectImage={data.imageKey}
|
projectImage={data.image}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+20
-9
@@ -1,9 +1,4 @@
|
|||||||
type MusicAPIResponse = {
|
// music type
|
||||||
data: {
|
|
||||||
tracks: MusicData[]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type MusicData = {
|
type MusicData = {
|
||||||
artist: {
|
artist: {
|
||||||
mbid: string,
|
mbid: string,
|
||||||
@@ -18,13 +13,29 @@ type MusicData = {
|
|||||||
url: string,
|
url: string,
|
||||||
image: MusicImage[]
|
image: MusicImage[]
|
||||||
}
|
}
|
||||||
|
|
||||||
type MusicImage = {
|
type MusicImage = {
|
||||||
size: string,
|
size: string,
|
||||||
"#text": string
|
"#text": string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tracker type
|
||||||
|
type ContentTrackerItem = {
|
||||||
|
id: number,
|
||||||
|
title: string,
|
||||||
|
author?: string,
|
||||||
|
description: string,
|
||||||
|
episode?: string,
|
||||||
|
image: string,
|
||||||
|
type: "tv" | "book" | "game",
|
||||||
|
tmdbId?: string,
|
||||||
|
yearReleased: number,
|
||||||
|
updatedAt: Date,
|
||||||
|
genre: string,
|
||||||
|
startedOn: Date,
|
||||||
|
finished: boolean
|
||||||
|
}
|
||||||
|
|
||||||
export type {
|
export type {
|
||||||
MusicAPIResponse,
|
MusicData,
|
||||||
MusicData
|
ContentTrackerItem
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user