Skip to content

Commit 6b9afad

Browse files
committed
adjust link styles
1 parent 6837dc2 commit 6b9afad

6 files changed

Lines changed: 96 additions & 85 deletions

File tree

‎frontend/main/src/components/ActiveLink.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import React, { Children } from 'react';
44

55
function ActiveLink({ router, children, ...props }: any) {
66
const child = Children.only(children);
7-
87
let className = child.props.className || '';
9-
if (router.asPath === props.href && props.activeClassName) {
8+
if (
9+
router.asPath.includes(props.comparison || props.href) &&
10+
props.activeClassName
11+
) {
1012
className = `${className} ${props.activeClassName}`.trim();
1113
}
1214

‎frontend/main/src/components/FirebaseAuth.tsx‎

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -138,22 +138,25 @@ export const AuthWrapper = ({
138138

139139
export const LoadingSpinner = () => {
140140
return (
141-
<svg
142-
role="status"
143-
className="inline w-8 h-8 mr-2 text-gray-200 animate-spin dark:text-gray-600 fill-purple-600"
144-
viewBox="0 0 100 101"
145-
fill="none"
146-
xmlns="http://www.w3.org/2000/svg"
147-
>
148-
<path
149-
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
150-
fill="currentColor"
151-
/>
152-
<path
153-
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
154-
fill="currentFill"
155-
/>
156-
</svg>
141+
<div className="flex p-2 text-xl font-bold bg-primary-500 text-basics-50">
142+
<svg
143+
role="status"
144+
className="inline w-8 h-8 mr-2 text-gray-200 animate-spin dark:text-gray-600 fill-purple-600"
145+
viewBox="0 0 100 101"
146+
fill="none"
147+
xmlns="http://www.w3.org/2000/svg"
148+
>
149+
<path
150+
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
151+
className="fill-primary-200"
152+
/>
153+
<path
154+
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
155+
className="fill-basics-50 dark:fill-basics-500"
156+
/>
157+
</svg>
158+
Loading...
159+
</div>
157160
);
158161
};
159162
export const signOut = (auth: Auth) =>

‎frontend/main/src/components/RecentPostsList.tsx‎

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Post, PostType } from '@/models/post.model';
2-
import { isActiveLink } from '@/utils/basics/links';
3-
import Link from 'next/link';
42
import { NextRouter } from 'next/router';
3+
import ActiveLink from '@/components/ActiveLink';
4+
import { isActiveLesson, isActiveLink } from '@/utils/basics/links';
55

66
export default function RecentPostsList({
77
posts,
@@ -10,52 +10,30 @@ export default function RecentPostsList({
1010
posts: Post[];
1111
router: NextRouter;
1212
}): JSX.Element {
13-
function link(post: Post) {
14-
switch (post._type) {
15-
case PostType.course:
16-
return (
17-
<>
18-
<Link href={`/course/${post.slug}`}>
19-
<a
20-
className={`no-underline border-none hover:underline flex p-1 rounded-md
21-
${
22-
isActiveLink(router, `/course/${post.slug}`)
23-
? 'bg-primary-200 text-basics-50'
24-
: 'bg-transparent '
25-
}
26-
`}
27-
>
28-
{post.title}
29-
</a>
30-
</Link>
31-
</>
32-
);
33-
default:
34-
return (
35-
<Link href={`/${post._type}/${post.slug}`}>
36-
<a
37-
className={`no-underline border-none hover:text-primary-900 hover:underline flex p-1 rounded-md
38-
${
39-
isActiveLink(
40-
router,
41-
`/${post._type}/${post.slug}`
42-
)
43-
? 'bg-primary-200 text-basics-50'
44-
: 'bg-transparent '
45-
}
46-
`}
47-
>
48-
{post.title}
49-
</a>
50-
</Link>
51-
);
52-
}
53-
}
5413
return (
5514
<>
5615
{posts.map((post) => (
57-
<li key={post._id} className="ml-0 list-none">
58-
{link(post)}
16+
<li
17+
key={post._id}
18+
className={`list-none cursor-pointer p-1 rounded m-1 flex flex-col justify-between
19+
${
20+
isActiveLink(router, `/${post._type}/${post.slug}`)
21+
? 'bg-primary-900 text-basics-50'
22+
: 'bg-transparent hover:bg-primary-900 hover:text-basics-50'
23+
}
24+
`}
25+
>
26+
<ActiveLink
27+
href={
28+
PostType.course
29+
? `/course/${post.slug}`
30+
: `/${post._type}/${post.slug}`
31+
}
32+
>
33+
<a className="no-underline border-none hover:text-basics-50 dark:hover:text-basics-50">
34+
{post.title}
35+
</a>
36+
</ActiveLink>
5937
</li>
6038
))}
6139
</>

‎frontend/main/src/components/user/AvatarMenu.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import Link from 'next/link';
22
import Image from 'next/image';
33

4-
import ActiveLink from '@/components/ActiveLink';
54
import { Dispatch, SetStateAction } from 'react';
65
import { useAuth, useSigninCheck } from 'reactfire';
76
import dynamic from 'next/dynamic';
87
import { signOut } from '@/components/FirebaseAuth';
8+
import ActiveLink from '@/components/ActiveLink';
99

1010
const AuthWrapper = dynamic<any>(
1111
() => import('@/components/FirebaseAuth').then((mod) => mod.AuthWrapper),
@@ -101,11 +101,11 @@ export default function AvatarMenu({
101101
aria-labelledby="user-menu"
102102
>
103103
<ActiveLink
104-
activeClassName="rounded first-child:text-primary-900"
104+
activeClassName="bg-primary-500 text-basics-50"
105105
href="/user/profile"
106106
>
107107
<a
108-
className="flex items-center p-2 text-sm rounded-md text-basics-900 hover:bg-primary-50 dark:hover:bg-primary-900 dark:hover:text-basics-50"
108+
className="flex items-center p-2 text-sm rounded-md hover:bg-primary-50 dark:hover:bg-primary-900 dark:hover:text-basics-50"
109109
role="menuitem"
110110
>
111111
<svg

‎frontend/main/src/layout/AppMenu.tsx‎

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,50 @@ export default function AppMenu({
9595
className="grid content-start h-full gap-4 p-4 bg-primary-900 dark:bg-primary-900"
9696
aria-label="Sidebar"
9797
>
98-
<ActiveLink activeClassName="" href="/courses">
99-
<a className="links-secondary" ref={focusme}>
98+
<ActiveLink
99+
activeClassName="bg-primary-500 rounded-sm"
100+
href="/courses"
101+
comparison="/course"
102+
>
103+
<a
104+
className="p-2 links-secondary hover:bg-primary-500"
105+
ref={focusme}
106+
>
100107
Courses
101108
</a>
102109
</ActiveLink>
103-
<ActiveLink activeClassName="" href="/tutorials">
104-
<a className="links-secondary">Tutorials</a>
110+
<ActiveLink
111+
activeClassName="bg-primary-500 rounded-sm"
112+
href="/tutorials"
113+
comparison="/tutorial"
114+
>
115+
<a className="p-2 links-secondary hover:bg-primary-500">
116+
Tutorials
117+
</a>
105118
</ActiveLink>
106-
<ActiveLink activeClassName="" href="/blog">
107-
<a className="links-secondary">Blog</a>
119+
<ActiveLink
120+
activeClassName="bg-primary-500 rounded-sm"
121+
href="/blog"
122+
comparison="/post"
123+
>
124+
<a className="p-2 links-secondary hover:bg-primary-500">Blog</a>
108125
</ActiveLink>
109-
<ActiveLink activeClassName="" href="/podcasts">
110-
<a className="links-secondary">Podcasts</a>
126+
<ActiveLink
127+
activeClassName="bg-primary-500 rounded-sm"
128+
href="/podcasts"
129+
comparison="/podcast"
130+
>
131+
<a className="p-2 links-secondary hover:bg-primary-500">
132+
Podcasts
133+
</a>
111134
</ActiveLink>
112-
<ActiveLink activeClassName="" href="/community">
113-
<a className="links-secondary">Community</a>
135+
<ActiveLink
136+
activeClassName="bg-primary-500 rounded-sm"
137+
href="/community"
138+
>
139+
<a className="p-2 links-secondary hover:bg-primary-500">
140+
Community
141+
</a>
114142
</ActiveLink>
115143
</nav>
116144
<section className="flex self-end p-4 bg-primary-700 dark:bg-primary-700">

‎frontend/main/src/layout/PostLayout.tsx‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,11 @@ export default function PostLayout({
188188
section.lessons.map((lesson) => (
189189
<li
190190
key={lesson._id}
191-
className={`list-none p-2 cursor-pointer hover:bg-primary-200 rounded m-1 flex flex-col justify-between
191+
className={`list-none cursor-pointer p-1 rounded m-1 flex flex-col justify-between
192192
${
193193
isActiveLesson(router, course, lesson)
194-
? 'bg-primary-200'
195-
: 'bg-transparent'
194+
? 'bg-primary-900 text-basics-50'
195+
: 'bg-transparent hover:bg-primary-900 hover:text-basics-50'
196196
}
197197
`}
198198
>
@@ -202,11 +202,11 @@ export default function PostLayout({
202202
passHref
203203
>
204204
<div className="flex gap-2">
205-
<a className="no-underline border-none hover:text-primary-900">
205+
<a className="no-underline border-none hover:text-basics-50 dark:hover:text-basics-50">
206206
{lesson.title}
207207
</a>
208208
{lesson?.access_mode && (
209-
<div className="no-underline hover:text-primary-900">
209+
<div className="no-underline ">
210210
{lesson?.access_mode != AccessMode.free && (
211211
<>
212212
{user && user.uid ? (
@@ -279,7 +279,7 @@ export default function PostLayout({
279279
{`Latest Courses`}
280280
</h2>
281281

282-
<ul className="grid grid-cols-1 gap-2 p-4 shadow-lg">
282+
<ul className="flex flex-col rounded-b rounded-tr grow bg-basics-50 dark:bg-basics-900 dark:text-primary-50 justify-items-stretch">
283283
<RecentPostsList
284284
router={router}
285285
posts={recentPosts[PostType.course]}
@@ -290,7 +290,7 @@ export default function PostLayout({
290290
<h2 className="w-full p-2 m-0 text-2xl font-bold xl:p-4 rounded-t-md xl:shrink-0 bg-secondary-600 text-basics-50">
291291
{`Latest Tutorials`}
292292
</h2>
293-
<ul className="grid grid-cols-1 gap-2 p-4 shadow-lg">
293+
<ul className="flex flex-col rounded-b rounded-tr grow bg-basics-50 dark:bg-basics-900 dark:text-primary-50 justify-items-stretch">
294294
<RecentPostsList
295295
router={router}
296296
posts={recentPosts[PostType.tutorial]}
@@ -301,7 +301,7 @@ export default function PostLayout({
301301
<h2 className="w-full p-2 m-0 text-2xl font-bold xl:p-4 rounded-t-md xl:shrink-0 bg-secondary-600 text-basics-50">
302302
{`Latest Podcasts`}
303303
</h2>
304-
<ul className="grid grid-cols-1 gap-2 p-4 shadow-lg">
304+
<ul className="flex flex-col rounded-b rounded-tr grow bg-basics-50 dark:bg-basics-900 dark:text-primary-50 justify-items-stretch">
305305
<RecentPostsList
306306
router={router}
307307
posts={recentPosts[PostType.podcast]}
@@ -312,7 +312,7 @@ export default function PostLayout({
312312
<h2 className="w-full p-2 m-0 text-2xl font-bold xl:p-4 rounded-t-md xl:shrink-0 bg-secondary-600 text-basics-50">
313313
{`Latest Blog`}
314314
</h2>
315-
<ul className="grid grid-cols-1 gap-2 p-4 shadow-lg">
315+
<ul className="flex flex-col rounded-b rounded-tr grow bg-basics-50 dark:bg-basics-900 dark:text-primary-50 justify-items-stretch">
316316
<RecentPostsList
317317
router={router}
318318
posts={recentPosts[PostType.post]}

0 commit comments

Comments
 (0)