Skip to content

Commit

Permalink
Add explicit error message
Browse files Browse the repository at this point in the history
  • Loading branch information
polypixeldev authored Nov 15, 2023
1 parent db57a06 commit bed3521
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {}
const nextConfig = {};

module.exports = nextConfig
module.exports = nextConfig;
2 changes: 1 addition & 1 deletion postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ module.exports = {
tailwindcss: {},
autoprefixer: {},
},
}
};
2 changes: 1 addition & 1 deletion src/app/add/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export async function POST(request: Request) {
const uri = JSON.stringify(trackRes.body.tracks?.items[0].uri);
if (process.env.DENY_EXPLICIT === "true") {
if (trackRes.body.tracks?.items[0].explicit) {
return;
return Response.json({ status: "explicit" });
}
}

Expand Down
20 changes: 9 additions & 11 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useState } from "react";
export default function Home() {
const [name, setName] = useState("");
const [artist, setArtist] = useState("");
const [success, setSuccess] = useState<boolean>();
const [status, setStatus] = useState<string>();

return (
<main className="flex min-h-screen flex-col items-center justify-start gap-16 bg-green-300 p-4 md:p-10">
Expand Down Expand Up @@ -55,29 +55,27 @@ export default function Home() {

const json = await res.json();

if (json.status == "ok") {
setName("");
setArtist("");
setSuccess(true);
} else {
setSuccess(false);
}
setStatus(json.status);
} catch {
setSuccess(false);
setStatus("error");
}
}}
>
Add
</button>
</form>
{success === true ? (
{status === "ok" ? (
<p className="text-bold w-full rounded-md bg-green-500 p-4 text-center text-xl">
Added song!
</p>
) : success === false ? (
) : status === "error" ? (
<p className="text-bold w-full rounded-md bg-red-500 p-4 text-center text-xl">
Error adding song, try again
</p>
) : status === "explicit" ? (
<p className="text-bold w-full rounded-md bg-red-500 p-4 text-center text-xl">
Song is explicit, try again
</p>
) : null}
</div>
<iframe
Expand Down

0 comments on commit bed3521

Please sign in to comment.