From bc2963f9e76a4000e3f1747b6fa4affdebba3956 Mon Sep 17 00:00:00 2001 From: real-zephex Date: Sun, 17 Mar 2024 07:08:55 +0530 Subject: prettified the code :) --- src/app/anime/page.js | 14 +++--- src/app/header/header.js | 17 ++++--- src/app/info/[id]/page.js | 26 +++++------ src/app/info/buttons.js | 9 ++-- src/app/info/page.js | 8 ++-- src/app/kdrama/api/fetchAnime.js | 18 ++++++-- src/app/kdrama/page.js | 29 ++++-------- src/app/layout.js | 6 +-- src/app/page.js | 8 ++-- src/app/recent/page.js | 51 +++++++++++---------- src/app/search/page.js | 99 ++++++++++++++++++++-------------------- src/app/top-airing/page.js | 51 +++++++++++---------- src/app/video/[animeId]/page.js | 78 +++++++++++++++++-------------- 13 files changed, 216 insertions(+), 198 deletions(-) (limited to 'src') diff --git a/src/app/anime/page.js b/src/app/anime/page.js index 06ea86f..759619d 100644 --- a/src/app/anime/page.js +++ b/src/app/anime/page.js @@ -1,14 +1,14 @@ -import './anime.css' -import Trending from '../top-airing/page' -import Releases from '../recent/page' -import Input from '../search/page' +import "./anime.css"; +import Trending from "../top-airing/page"; +import Releases from "../recent/page"; +import Input from "../search/page"; export default async function Anime() { return (
- +
- ) -} \ No newline at end of file + ); +} diff --git a/src/app/header/header.js b/src/app/header/header.js index 03d1328..bc4a019 100644 --- a/src/app/header/header.js +++ b/src/app/header/header.js @@ -1,11 +1,16 @@ -import Link from "next/link" +import Link from "next/link"; export default function Header() { return (
- -

Dramalama

+ +

+ Dramalama +

@@ -16,7 +21,7 @@ export default function Header() {
-
+
- ) -} \ No newline at end of file + ); +} diff --git a/src/app/info/[id]/page.js b/src/app/info/[id]/page.js index 9d37819..e49443f 100644 --- a/src/app/info/[id]/page.js +++ b/src/app/info/[id]/page.js @@ -1,8 +1,8 @@ -import "../info.css" +import "../info.css"; import Image from "next/image"; import CreateButton from "../buttons"; -export default async function AnimeInfo({params}) { +export default async function AnimeInfo({ params }) { let animeID = params.id; const info = await getAnimeInfo(animeID); @@ -14,32 +14,32 @@ export default async function AnimeInfo({params}) {

{info.title}

- Drama
-

- {info.description} -

+

{info.description}

)}
- {info && info.episodes.map((item, index) => ( - - ))} + {info && + info.episodes.map((item, index) => ( + + ))}
- - ) + ); } async function getAnimeInfo(anime_id) { - const res = await fetch("https://anime-sensei-api.vercel.app/anime/gogoanime/info/" + anime_id); + const res = await fetch( + "https://anime-sensei-api.vercel.app/anime/gogoanime/info/" + anime_id + ); const data = res.json(); return data; -} \ No newline at end of file +} diff --git a/src/app/info/buttons.js b/src/app/info/buttons.js index 8f041a8..6244a2e 100644 --- a/src/app/info/buttons.js +++ b/src/app/info/buttons.js @@ -1,13 +1,10 @@ -"use client" +"use client"; import Link from "next/link"; export default function CreateButton({ a }) { - return ( - + ); -} \ No newline at end of file +} diff --git a/src/app/info/page.js b/src/app/info/page.js index 1468652..9004ade 100644 --- a/src/app/info/page.js +++ b/src/app/info/page.js @@ -1,11 +1,11 @@ -import './info.css' +import "./info.css"; export default function Info() { return ( -
+

This is the anime info page. This page will display information about the queried anime when anime id is passed along the url.

- ) -} \ No newline at end of file + ); +} diff --git a/src/app/kdrama/api/fetchAnime.js b/src/app/kdrama/api/fetchAnime.js index 903ca18..fcfc014 100644 --- a/src/app/kdrama/api/fetchAnime.js +++ b/src/app/kdrama/api/fetchAnime.js @@ -1,15 +1,25 @@ export async function fetchAnimeInfo(title) { - const res = await fetch("https://dramalama-api.vercel.app/movies/dramacool/" + title) + const res = await fetch( + "https://dramalama-api.vercel.app/movies/dramacool/" + title + ); const data = await res.json(); return data; } export async function fetchDramaInfo(id) { - const res = (await fetch(`https://dramalama-api.vercel.app/movies/dramacool/info?id=${id}`)).json() + const res = ( + await fetch( + `https://dramalama-api.vercel.app/movies/dramacool/info?id=${id}` + ) + ).json(); return res; } export async function fetchVideoLinks(drama_id, episode_id) { - const res = (await (fetch(`https://dramalama-api.vercel.app/movies/dramacool/watch?episodeId=${episode_id}&mediaId=${drama_id}`))).json() + const res = ( + await fetch( + `https://dramalama-api.vercel.app/movies/dramacool/watch?episodeId=${episode_id}&mediaId=${drama_id}` + ) + ).json(); return res; -} \ No newline at end of file +} diff --git a/src/app/kdrama/page.js b/src/app/kdrama/page.js index 3877453..129c913 100644 --- a/src/app/kdrama/page.js +++ b/src/app/kdrama/page.js @@ -1,11 +1,11 @@ -"use client" +"use client"; -import "./kdrama.css" +import "./kdrama.css"; import { useState } from "react"; import ReactPlayer from "react-player"; -import Image from 'next/image'; -import { FaSearch } from 'react-icons/fa'; // Import the search icon from react-icons library +import Image from "next/image"; +import { FaSearch } from "react-icons/fa"; // Import the search icon from react-icons library import { fetchAnimeInfo, @@ -14,7 +14,6 @@ import { } from "./api/fetchAnime.js"; export default function Kdrama() { - const [searchTitle, setSearchTitle] = useState(""); const [searchedDrama, setSearchedDrama] = useState(null); async function handleKeyPresses(event) { @@ -50,7 +49,7 @@ export default function Kdrama() { return (
- + setSearchTitle(event.target.value)} @@ -59,17 +58,12 @@ export default function Kdrama() {
-

- Start by searching for some dramas -

-

- Look for the search box above. -

+

Start by searching for some dramas

+

Look for the search box above.

- {videoLink && (
-

- {details.title} -

+

{details.title}

- - ) -} \ No newline at end of file + ); +} diff --git a/src/app/layout.js b/src/app/layout.js index d6dd022..3c36ca3 100644 --- a/src/app/layout.js +++ b/src/app/layout.js @@ -5,14 +5,14 @@ import Header from "./header/header"; const inter = Inter({ subsets: ["latin"] }); export const metadata = { - title: "Dramalama-Next", + title: "Dramalama V2.0", description: "Rewrite of dramalama in next", }; export default function RootLayout({ children }) { - return ( + return ( - +
{children} diff --git a/src/app/page.js b/src/app/page.js index f8750b9..03a1035 100644 --- a/src/app/page.js +++ b/src/app/page.js @@ -10,11 +10,11 @@ export default function Home() { width={300} height={300} alt="Logo" - > - + >

- Welcome to dramalama. An online service where you can watch kdramas and anime for free. -

+ Welcome to dramalama. An online service where you can watch + kdramas and anime for free. +

); diff --git a/src/app/recent/page.js b/src/app/recent/page.js index 0cefca5..2962e0f 100644 --- a/src/app/recent/page.js +++ b/src/app/recent/page.js @@ -3,39 +3,42 @@ import Image from "next/image"; import Link from "next/link"; export default async function Releases() { - const data = await test(); return (
-

- Recent Releases -

+

Recent Releases

- {data && data.results.map((item, index) => ( - -
- Drama -

- {item.title} -

-
- - ))} + {data && + data.results.map((item, index) => ( + +
+ Drama +

{item.title}

+
+ + ))}
- )} + ); +} async function test() { - const res = await fetch("https://dramalama-api.vercel.app/anime/gogoanime/recent-episodes"); + const res = await fetch( + "https://dramalama-api.vercel.app/anime/gogoanime/recent-episodes" + ); const data = res.json(); return data; -} \ No newline at end of file +} diff --git a/src/app/search/page.js b/src/app/search/page.js index f384d85..e6d4f08 100644 --- a/src/app/search/page.js +++ b/src/app/search/page.js @@ -1,93 +1,92 @@ -"use client" +"use client"; -import './search.css' -import { FaSearch } from 'react-icons/fa'; // Import the search icon from react-icons library -import { useState } from 'react'; -import Image from 'next/image'; -import Link from 'next/link'; +import "./search.css"; +import { FaSearch } from "react-icons/fa"; // Import the search icon from react-icons library +import { useState } from "react"; +import Image from "next/image"; +import Link from "next/link"; export default function Input() { - - const [searchedAnime, setSearchedAnime] = useState(null) - const [loading, setLoading] = useState(null) + const [searchedAnime, setSearchedAnime] = useState(null); + const [loading, setLoading] = useState(null); const handleKeyPress = (event) => { if ( - (event.code === "Enter" || - event.key === "Enter" || - event.code === 13) && + (event.code === "Enter" || + event.key === "Enter" || + event.code === 13) && searchedAnime != "" ) { - fetch_animes(searchedAnime) + fetch_animes(searchedAnime); } else if ( - (event.code === "Enter" || - event.key === "Enter" || - event.code === 13) && + (event.code === "Enter" || + event.key === "Enter" || + event.code === 13) && searchedAnime === "" - ) { - alert("Input cannot be empty") + ) { + alert("Input cannot be empty"); } - } + }; const [search1, setSearch] = useState(null); const fetch_animes = (title) => { fetch("https://dramalama-api.vercel.app/anime/gogoanime/" + title) .then(setLoading(true)) - .then(res => res.json()) - .then( - data => { - setSearch(data) - setLoading(false) - } - ) - } + .then((res) => res.json()) + .then((data) => { + setSearch(data); + setLoading(false); + }); + }; return (
-
-
- - setSearchedAnime(event.target.value)} +
+
+ + + setSearchedAnime(event.target.value) + } onKeyDown={(event) => handleKeyPress(event)} - placeholder='Enter anime title'> - - + placeholder="Enter anime title" + >
- {loading && ( -

- Please wait while we crunch all the data for you. +

+ Please wait while we crunch all the data for you.

)} -
+
{search1 ? ( search1.results && search1.results.length > 0 ? ( search1.results.map((item, index) => ( - -
+ +

{item.title}

- Drama Poster
)) ) : ( -
-

No results found

+
+

No results found

) ) : null}
-
- - ) -} \ No newline at end of file + ); +} diff --git a/src/app/top-airing/page.js b/src/app/top-airing/page.js index e564e16..b9d54cd 100644 --- a/src/app/top-airing/page.js +++ b/src/app/top-airing/page.js @@ -3,39 +3,42 @@ import Image from "next/image"; import Link from "next/link"; export default async function Trending() { - const data = await test(); return (
-

- Trending -

+

Trending

- {data && data.results.map((item, index) => ( - -
- Drama -

- {item.title} -

-
- - ))} + {data && + data.results.map((item, index) => ( + +
+ Drama +

{item.title}

+
+ + ))}
- )} + ); +} async function test() { - const res = await fetch("https://dramalama-api.vercel.app/anime/gogoanime/top-airing"); + const res = await fetch( + "https://dramalama-api.vercel.app/anime/gogoanime/top-airing" + ); const data = res.json(); return data; -} \ No newline at end of file +} diff --git a/src/app/video/[animeId]/page.js b/src/app/video/[animeId]/page.js index af7e690..4cd74ce 100644 --- a/src/app/video/[animeId]/page.js +++ b/src/app/video/[animeId]/page.js @@ -1,51 +1,61 @@ -"use client" +"use client"; -import '../video.css' -import React, { useState, useEffect } from 'react'; -import ReactPlayer from 'react-player'; +import "../video.css"; +import React, { useState, useEffect } from "react"; +import ReactPlayer from "react-player"; export default function Video({ params }) { - const id = params.animeId; - const [videoLink, setVideoLink] = useState(null); - const [loading, setLoading] = useState(true); + const id = params.animeId; + const [videoLink, setVideoLink] = useState(null); + const [loading, setLoading] = useState(true); const [epi, setEpi] = useState(""); - - useEffect(() => { - fetch("https://anime-sensei-api.vercel.app/anime/gogoanime/watch/" + id) - .then(res => res.json()) - .then(data => { - const words = id.split("-") + useEffect(() => { + fetch("https://anime-sensei-api.vercel.app/anime/gogoanime/watch/" + id) + .then((res) => res.json()) + .then((data) => { + const words = id.split("-"); const last_two = words.slice(-2).join(" "); const remainingWords = words.slice(0, -2).join(" "); - setEpi([last_two, remainingWords]) - setVideoLink(data.sources[3].url); - setLoading(false); - }) - .catch(error => { - console.log("Some error occured", error); - setLoading(false); - }); - }, [id]); + setEpi([last_two, remainingWords]); + setVideoLink(data.sources[3].url); + setLoading(false); + }) + .catch((error) => { + console.log("Some error occured", error); + setLoading(false); + }); + }, [id]); - return ( -
- {loading && ( -

Loading...

- )} + return ( +
+ {loading && ( +

+ Loading... +

+ )} {videoLink && ( -
-

{epi[0]} - {epi[1]}

- +

+ {epi[0]} - {epi[1]} +

+
)} -
- ); +
+ ); } -- cgit v1.2.3