Skip to content

Commit

Permalink
New Player, User Settings and More
Browse files Browse the repository at this point in the history
### What's New

- Player Replaced 
- Change User Photo and Username
- "Keep Watching" Section on Home Page
- History/Latests Watched Page

### Fixes
- Minor Fixes on Css
- Manga Page not Showing Error Message
  • Loading branch information
ErickLimaS authored Mar 17, 2024
2 parents aef4029 + 42b601d commit 8d76da0
Show file tree
Hide file tree
Showing 37 changed files with 1,677 additions and 168 deletions.
57 changes: 39 additions & 18 deletions api/anilist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,29 @@ type ErrorTypes = {
}
}

// returns medias which is adult
function filterAdultContent(data: any[], reponseType?: "mediaByFormat") {

let filtered

if (reponseType == "mediaByFormat") {

filtered = data.filter((item) => item.isAdult == false)

}
else {
filtered = data.filter((item) => item.media.isAdult == false)
}

return filtered

}

// eslint-disable-next-line import/no-anonymous-default-export
export default {

// HOME PAGE
getNewReleases: cache(async (type: string, format?: string, sort?: string) => {
getNewReleases: cache(async (type: string, format?: string, sort?: string, showAdultContent?: boolean) => {

const season: string = getCurrentSeason()

Expand All @@ -42,7 +60,7 @@ export default {
'perPage': 20,
'season': `${season}`,
'seasonYear': `${new Date().getFullYear()}`,
'showAdultContent': false
'showAdultContent': showAdultContent || false
}
}

Expand All @@ -64,7 +82,7 @@ export default {
}),

//SEARCH
getSeachResults: cache(async (query: string) => {
getSeachResults: cache(async (query: string, showAdultContent?: boolean) => {

try {

Expand All @@ -74,7 +92,7 @@ export default {
'page': 1,
'sort': 'TRENDING_DESC',
'perPage': 10,
'showAdultContent': false,
'showAdultContent': showAdultContent == true ? undefined : false,
'search': query
}
}
Expand All @@ -86,7 +104,8 @@ export default {
data: graphqlQuery
})

return data.data.Page.media as ApiDefaultResult[]
return showAdultContent ?
data.data.Page.media as ApiDefaultResult[] : filterAdultContent(data.data.Page.media)

}
catch (error) {
Expand All @@ -97,7 +116,7 @@ export default {
}),

// RELEASING THIS WEEK
getReleasingThisWeek: cache(async (type: string, format?: string, page?: number) => {
getReleasingThisWeek: cache(async (type: string, format?: string, page?: number, showAdultContent?: boolean) => {

try {

Expand All @@ -110,7 +129,7 @@ export default {
'page': page || 1,
'sort': 'TRENDING_DESC',
'perPage': 10,
'showAdultContent': false,
'showAdultContent': showAdultContent || false,
'season': getCurrentSeason(),
'year': thisYear
}
Expand All @@ -135,7 +154,7 @@ export default {
}),

// RELEASING BY DAYS RANGE
getReleasingByDaysRange: cache(async (type: string, days: number, pageNumber?: number, perPage?: number) => {
getReleasingByDaysRange: cache(async (type: string, days: 1 | 7 | 30, pageNumber?: number, perPage?: number, showAdultContent?: boolean) => {

try {

Expand All @@ -151,7 +170,7 @@ export default {
'perPage': perPage || 5,
'type': type,
'sort': "EPISODE",
'showAdultContent': false,
'showAdultContent': showAdultContent == true ? undefined : false,
'airingAt_greater': dateInUnix,
'airingAt_lesser': lastHourOfTheDay(1) // returns today last hour
}
Expand All @@ -164,7 +183,8 @@ export default {
data: graphqlQuery
})

return data.data.Page.airingSchedules as ApiAiringMidiaResults[]
return showAdultContent ?
data.data.Page.airingSchedules as ApiAiringMidiaResults[] : filterAdultContent(data.data.Page.airingSchedules) as ApiAiringMidiaResults[]

}
catch (error) {
Expand All @@ -176,7 +196,7 @@ export default {
}),

// TRENDING
getTrendingMedia: cache(async (sort?: string) => {
getTrendingMedia: cache(async (sort?: string, showAdultContent?: boolean) => {

try {

Expand All @@ -188,7 +208,7 @@ export default {
'page': 1,
'sort': sort || 'TRENDING_DESC',
'perPage': 20,
'showAdultContent': false,
'showAdultContent': showAdultContent == true ? undefined : false,
'season': getCurrentSeason(),
'year': thisYear
}
Expand All @@ -213,7 +233,7 @@ export default {
}),

// MEDIAS IN THIS FORMAT
getMediaForThisFormat: cache(async (type: string, sort?: string, pageNumber?: number, perPage?: number) => {
getMediaForThisFormat: cache(async (type: string, sort?: string, pageNumber?: number, perPage?: number, showAdultContent?: boolean) => {

try {

Expand All @@ -223,7 +243,7 @@ export default {
'page': pageNumber || 1,
'sort': sort || 'TRENDING_DESC',
'perPage': perPage || 20,
'showAdultContent': false,
'showAdultContent': showAdultContent == true ? undefined : false,
'type': type
}
}
Expand All @@ -235,7 +255,9 @@ export default {
data: graphqlQuery
})

return data.data.Page.media as ApiDefaultResult[]
return showAdultContent ?
data.data.Page.media as ApiDefaultResult[] : filterAdultContent(data.data.Page.media, "mediaByFormat") as ApiDefaultResult[]

}
catch (error) {

Expand All @@ -245,15 +267,14 @@ export default {
}),

// GET INFO OF anime/movie/manga by ID
getMediaInfo: cache(async (id: number) => {
getMediaInfo: cache(async (id: number, showAdultContent?: boolean) => {

try {

const graphqlQuery = {
"query": mediaByIdQueryRequest('$id: Int', 'id: $id'),
"variables": {
'id': id,
'showAdultContent': false
'id': id
}
}

Expand Down
46 changes: 46 additions & 0 deletions app/components/HomePage/KeepWatchingSection/component.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* KEEP WATCHING */
#keep_watching_container {
width: 96%;

margin: auto;

margin-bottom: 32px;

padding-top: 32px;

justify-items: center;
justify-content: center;

}

@media((min-width: 576px) and (max-width: 768px)) {
#keep_watching_container {
width: var(--breakpoint-sm);
}
}

@media((min-width: 992px) and (max-width: 1200px)) {
#keep_watching_container {
width: var(--breakpoint-md);
}
}

@media((min-width: 1201px) and (max-width: 1400px)) {
#keep_watching_container {
width: var(--breakpoint-xl);
}
}

@media((min-width: 1441px)) {
#keep_watching_container {
width: var(--breakpoint-xxl);
}
}

#keep_watching_container>h2 {
font-size: var(--font-size--h3);

color: var(--white-100);

margin-bottom: 24px;
}
94 changes: 94 additions & 0 deletions app/components/HomePage/KeepWatchingSection/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
"use client"
import React, { useEffect, useState } from 'react'
import SwiperListContainer from '../../SwiperListContainer'
import styles from "./component.module.css"
import { AnimatePresence, motion } from 'framer-motion'
import { getAuth } from 'firebase/auth'
import { useAuthState } from 'react-firebase-hooks/auth'
import { doc, getDoc, getFirestore } from 'firebase/firestore'
import { initFirebase } from '@/firebase/firebaseApp'

function KeepWatchingSection() {

const auth = getAuth()

const [user] = useAuthState(auth)

const db = getFirestore(initFirebase());

const [watchingList, setWatchingList] = useState<KeepWatchingItem[]>([])

const motionVariants = {
initial: {
opacity: 0,
height: 0
},
animate: {
opacity: 1,
height: "auto",
transition: {
staggerChildren: 0.1,
},
}
}

async function getWatchingList() {

const userDoc = await getDoc(doc(db, "users", user!.uid))

const watchingList = userDoc.get("keepWatching")

let listFromObjectToArray = Object.keys(watchingList).map(key => {

return watchingList[key]

})

// removes any empty object
listFromObjectToArray = listFromObjectToArray.filter(item => item.length != 0 && item)

// sort by update date
listFromObjectToArray = listFromObjectToArray.sort(function (x: KeepWatchingItem, y: KeepWatchingItem) {
return x.updatedAt - y.updatedAt
}).reverse()

setWatchingList(listFromObjectToArray || null)

}

useEffect(() => {

if (user) getWatchingList()

}, [user])

return (
<AnimatePresence
initial={false}
>
{(user && watchingList!.length > 0) && (
<motion.section
id={styles.keep_watching_container}
variants={motionVariants}
initial={"initial"}
animate={"animate"}
>

<h2>Keep Watching</h2>

<div>

<SwiperListContainer
keepWatchingVariant={true}
data={watchingList}
/>

</div>

</motion.section>
)}
</AnimatePresence>
)
}

export default KeepWatchingSection
24 changes: 21 additions & 3 deletions app/components/HomePage/MediaRankingSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import MediaListCoverInfo from '../../MediaItemCoverInfo2'
import NavButtons from '../../NavButtons'
import { ApiDefaultResult } from '@/app/ts/interfaces/apiAnilistDataInterface'
import API from "@/api/anilist"
import { useAuthState } from 'react-firebase-hooks/auth'
import { getAuth } from 'firebase/auth'
import { initFirebase } from '@/firebase/firebaseApp'
import { doc, getDoc, getFirestore } from 'firebase/firestore'

type PropsTypes = {

Expand All @@ -20,26 +24,40 @@ function MediaRankingSection(props: PropsTypes) {
let { data } = props
let currentQueryValue = "ANIME"

const auth = getAuth()
const [user] = useAuthState(auth)

const db = getFirestore(initFirebase())

useEffect(() => {
setMediaList(data as ApiDefaultResult[])
}, [])

// request new type of media then set them
const loadMedia: (parameter: string) => void = async (parameter: string) => {

const response = await API.getMediaForThisFormat(parameter).then(res => ((res as ApiDefaultResult[]).filter((item) => item.isAdult == false)))
let showAdultContent = false

if (user) {

showAdultContent = await getDoc(doc(db, 'users', user!.uid)).then(doc => doc.get("showAdultContent"))

}

const response: ApiDefaultResult[] | void = await API.getMediaForThisFormat(parameter, undefined, undefined, undefined, showAdultContent)

currentQueryValue = parameter

setMediaList(response)
setMediaList(response as ApiDefaultResult[])

}

return (
<div id={styles.rank_container}>

<div className={styles.title_navbar_container}>

<h3>Top 10 this week</h3>
<h3>Top 10 This Week</h3>

<NavButtons
functionReceived={loadMedia as (parameter: string | number) => void}
Expand Down
Loading

0 comments on commit 8d76da0

Please sign in to comment.