1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
import { useSearch } from "@/lib/context/isOpenState";
import { getCurrentSeason } from "@/utils/getTimes";
import { ArrowLeftIcon, ArrowUpCircleIcon } from "@heroicons/react/20/solid";
import { UserIcon } from "@heroicons/react/24/solid";
import { signIn, signOut, useSession } from "next-auth/react";
import Image from "next/image";
import Link from "next/link";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";
const getScrollPosition = (el = window) => ({
x: el.pageXOffset !== undefined ? el.pageXOffset : el.scrollLeft,
y: el.pageYOffset !== undefined ? el.pageYOffset : el.scrollTop,
});
export function NewNavbar({
info,
scrollP = 200,
toTop = false,
withNav = false,
paddingY = "py-3",
home = false,
back = false,
manga = false,
shrink = false,
}) {
const { data: session } = useSession();
const router = useRouter();
const [scrollPosition, setScrollPosition] = useState();
const { setIsOpen } = useSearch();
const year = new Date().getFullYear();
const season = getCurrentSeason();
useEffect(() => {
const handleScroll = () => {
setScrollPosition(getScrollPosition());
};
// Add a scroll event listener when the component mounts
window.addEventListener("scroll", handleScroll);
// Clean up the event listener when the component unmounts
return () => {
window.removeEventListener("scroll", handleScroll);
};
}, []);
return (
<>
<nav
className={`${home ? "" : "fixed"} z-[200] top-0 px-5 w-full ${
scrollPosition?.y >= scrollP
? home
? ""
: `bg-tersier shadow-tersier shadow-sm ${
shrink ? "py-1" : `${paddingY}`
}`
: `${paddingY}`
} transition-all duration-200 ease-linear`}
>
<div
className={`flex items-center justify-between mx-auto ${
home ? "lg:max-w-[90%] gap-10" : "max-w-screen-2xl"
}`}
>
<div
className={`flex items-center ${
withNav ? `${home ? "" : "w-[20%]"} gap-8` : " w-full gap-4"
}`}
>
{info ? (
<>
<button
type="button"
className="flex-center w-7 h-7 text-white"
onClick={() => {
back
? router.back()
: manga
? router.push("/en/search/manga")
: router.push("/en");
}}
>
<ArrowLeftIcon className="w-full h-full" />
</button>
<span
className={`font-inter font-semibold w-[50%] line-clamp-1 select-none ${
scrollPosition?.y >= scrollP + 80
? "opacity-100"
: "opacity-0"
} transition-all duration-200 ease-linear`}
>
{info.title.romaji}
</span>
</>
) : (
// <></>
<Link
href={"/en"}
className={`flex-center font-outfit font-semibold pb-2 ${
home ? "text-4xl text-action" : "text-white text-3xl"
}`}
>
moopa
</Link>
)}
</div>
{withNav && (
<ul
className={`hidden w-full items-center gap-10 pt-2 font-outfit text-[14px] lg:pt-0 lg:flex ${
home ? "justify-start" : "justify-center"
}`}
>
<li>
<Link
href={`/en/search/anime?season=${season}&year=${year}`}
className="hover:text-action/80 transition-all duration-150 ease-linear"
>
This Season
</Link>
</li>
<li>
<Link
href="/en/search/manga"
className="hover:text-action/80 transition-all duration-150 ease-linear"
>
Manga
</Link>
</li>
<li>
<Link
href="/en/search/anime"
className="hover:text-action/80 transition-all duration-150 ease-linear"
>
Anime
</Link>
</li>
<li>
<Link
href="/en/schedule"
className="hover:text-action/80 transition-all duration-150 ease-linear"
>
Schedule
</Link>
</li>
{!session && (
<li>
<button
onClick={() => signIn("AniListProvider")}
className="hover:text-action/80 transition-all duration-150 ease-linear"
// className="px-2 py-1 ring-1 ring-action font-bold font-karla rounded-md"
>
Sign In
</button>
</li>
)}
{session && (
<li className="text-center">
<Link
href={`/en/profile/${session?.user.name}`}
className="hover:text-action/80 transition-all duration-150 ease-linear"
>
My List
</Link>
</li>
)}
</ul>
)}
<div className="flex w-[20%] justify-end items-center gap-4">
<button
type="button"
title="Search"
onClick={() => setIsOpen(true)}
className="flex-center w-[26px] h-[26px]"
>
<svg
xmlns="http://www.w3.org/2000/svg"
width="32"
height="32"
viewBox="0 0 24 24"
>
<path
fill="none"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M15 15l6 6m-11-4a7 7 0 110-14 7 7 0 010 14z"
></path>
</svg>
</button>
{/* <div
className="bg-white"
// title={sessions ? "Go to Profile" : "Login With AniList"}
> */}
{session ? (
<div className="w-7 h-7 relative flex flex-col items-center group shrink-0">
<button
type="button"
onClick={() =>
router.push(`/en/profile/${session?.user.name}`)
}
className="rounded-full bg-white/30 overflow-hidden"
>
<Image
src={session?.user.image.large}
alt="avatar"
width={50}
height={50}
className="w-full h-full object-cover"
/>
</button>
<div className="hidden absolute z-50 w-28 text-center -bottom-20 text-white shadow-2xl opacity-0 bg-secondary p-1 py-2 rounded-md font-karla font-light invisible group-hover:visible group-hover:opacity-100 duration-300 transition-all md:grid place-items-center gap-1">
<Link
href={`/en/profile/${session?.user.name}`}
className="hover:text-action"
>
Profile
</Link>
<button
type="button"
onClick={() => signOut("AniListProvider")}
className="hover:text-action"
>
Log out
</button>
</div>
</div>
) : (
<button
type="button"
onClick={() => signIn("AniListProvider")}
title="Login With AniList"
className="w-7 h-7 bg-white/30 rounded-full overflow-hidden shrink-0"
>
<UserIcon className="w-full h-full translate-y-1" />
</button>
)}
{/* </div> */}
</div>
</div>
</nav>
{toTop && (
<button
type="button"
onClick={() => {
window.scrollTo({
top: 0,
behavior: "smooth",
});
}}
className={`${
scrollPosition?.y >= 180
? "-translate-x-6 opacity-100"
: "translate-x-[100%] opacity-0"
} transform transition-all duration-300 ease-in-out fixed bottom-24 lg:bottom-14 right-0 z-[500]`}
>
<ArrowUpCircleIcon className="w-10 h-10 text-white" />
</button>
)}
</>
);
}
|