use api for project requests
This commit is contained in:
@@ -53,7 +53,7 @@ export default function RecentListens() {
|
|||||||
if (data) {
|
if (data) {
|
||||||
return (
|
return (
|
||||||
<a href={data[0].url} target="_blank">
|
<a href={data[0].url} target="_blank">
|
||||||
<div className="bg-white text-black p-4">
|
<div className="bg-white text-black p-4 max-w-fit lg:max-w-full mx-auto">
|
||||||
{
|
{
|
||||||
(loading) ? (
|
(loading) ? (
|
||||||
<h1>Loading..</h1>
|
<h1>Loading..</h1>
|
||||||
|
|||||||
@@ -1,12 +1,5 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
|
|
||||||
type PhotoDataResponse = {
|
|
||||||
result: {
|
|
||||||
data: {
|
|
||||||
json: PhotoData[]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
type PhotoData = {
|
type PhotoData = {
|
||||||
id: number,
|
id: number,
|
||||||
name: string,
|
name: string,
|
||||||
@@ -15,12 +8,12 @@ type PhotoData = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function RecentPhoto() {
|
export default function RecentPhoto() {
|
||||||
const [ data, setData ] = useState<PhotoData[] | null>(null);
|
const [ data, setData ] = useState<PhotoData | null>(null);
|
||||||
const [ loading, setLoading ] = useState<boolean>(true);
|
const [ loading, setLoading ] = useState<boolean>(true);
|
||||||
const [ errorState, setErrorState ] = useState<string | null>(null);
|
const [ errorState, setErrorState ] = useState<string | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch("https://photos-cors.alexav.gg", {
|
fetch("https://api.alexav.gg/v4/social/photos", {
|
||||||
method: 'get',
|
method: 'get',
|
||||||
headers: {
|
headers: {
|
||||||
'content-type': 'application/json'
|
'content-type': 'application/json'
|
||||||
@@ -29,8 +22,8 @@ export default function RecentPhoto() {
|
|||||||
.then(async (res) => {
|
.then(async (res) => {
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
console.log("ok!")
|
console.log("ok!")
|
||||||
const json = await res.json() as PhotoDataResponse[];
|
const json = await res.json()
|
||||||
setData(json[0].result.data.json);
|
setData(json.data[0]);
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
} else {
|
} else {
|
||||||
console.log("not ok :(")
|
console.log("not ok :(")
|
||||||
@@ -43,6 +36,9 @@ export default function RecentPhoto() {
|
|||||||
setErrorState(e.message)
|
setErrorState(e.message)
|
||||||
})
|
})
|
||||||
}, []);
|
}, []);
|
||||||
|
useEffect(() => {
|
||||||
|
console.log(data)
|
||||||
|
}, [data])
|
||||||
|
|
||||||
const parseDate = (date: Date) => {
|
const parseDate = (date: Date) => {
|
||||||
const jsDate = new Date(date);
|
const jsDate = new Date(date);
|
||||||
@@ -51,20 +47,20 @@ export default function RecentPhoto() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<a href={"https://photos.alexav.gg/"} target="_blank">
|
<a href={"https://photos.alexav.gg/"} target="_blank">
|
||||||
<div className="bg-white text-black p-4">
|
<div className="bg-white text-black p-4 max-w-fit lg:max-w-full mx-auto">
|
||||||
{
|
{
|
||||||
(loading) ? (
|
(loading) ? (
|
||||||
<h1>Loading..</h1>
|
<h1>Loading..</h1>
|
||||||
) : (!errorState && data) ? (
|
) : (!errorState && data) ? (
|
||||||
<div className="flex items-center">
|
<div className="flex items-center">
|
||||||
<img
|
<img
|
||||||
src={data[0].imageUrl}
|
src={data.imageUrl}
|
||||||
width="200"
|
width="200"
|
||||||
/>
|
/>
|
||||||
<div className="flex flex-wrap mx-2">
|
<div className="flex flex-wrap mx-2">
|
||||||
<h1 className="w-full font-bold">{data[0].name}</h1>
|
<h1 className="w-full font-bold">{data.name}</h1>
|
||||||
|
|
||||||
<h1>{parseDate(data[0].dateTaken as Date)}</h1>
|
<h1>{parseDate(data.dateTaken as Date)}</h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
|
|
||||||
type WatchDataResponse = {
|
type WatchDataResponse = {
|
||||||
result: {
|
status: number,
|
||||||
data: {
|
data: WatchData
|
||||||
json: WatchData
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
type WatchData = {
|
type WatchData = {
|
||||||
id: number,
|
id: number,
|
||||||
@@ -27,13 +24,13 @@ export default function RecentWatch() {
|
|||||||
const [ errorState, setErrorState ] = useState<string>("");
|
const [ errorState, setErrorState ] = useState<string>("");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch("https://watch-cors.alexav.gg", {
|
fetch("https://api.alexav.gg/v4/social/watch", {
|
||||||
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() as WatchDataResponse;
|
||||||
setData(json.result.data.json);
|
setData(json.data);
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
} else {
|
} else {
|
||||||
setErrorState("Failed to fetch data!");
|
setErrorState("Failed to fetch data!");
|
||||||
@@ -53,7 +50,7 @@ export default function RecentWatch() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<a href={data?.id ? "https://watch.alexav.gg/?id=" + data?.id : "#"} target="_blank">
|
<a href={data?.id ? "https://watch.alexav.gg/?id=" + data?.id : "#"} target="_blank">
|
||||||
<div className="bg-white text-black p-4">
|
<div className="bg-white text-black p-4 max-w-fit lg:max-w-full mx-auto">
|
||||||
{
|
{
|
||||||
loading ? (
|
loading ? (
|
||||||
<h1>Loading..</h1>
|
<h1>Loading..</h1>
|
||||||
|
|||||||
Reference in New Issue
Block a user