Skip to content

Commit 0e73347

Browse files
Dark mode (#1154)
* create theme context * create theme toggle btn * update: tailwind dark theme classes * fixes: toggling & icon update * update dark mode in components & pages * typo fixes
1 parent 5c124e8 commit 0e73347

25 files changed

+302
-97
lines changed

frontend/src/components/AboutUser.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ const AboutUser = ({ className, bio, social_links, joinedAt }) => {
1212
let link = social_links[key];
1313
return link ?
1414
<Link to={link} key={key} target="_blank">
15-
<i className={"fi " + (key !== 'website' ? "fi-brands-" + key : "fi-rr-globe") + " text-2xl hover:text-black"} ></i>
15+
<i
16+
className={
17+
"fi " +
18+
(key !== 'website' ? "fi-brands-" + key : "fi-rr-globe") +
19+
" text-2xl text-gray-700 dark:text-gray-300 hover:text-black dark:hover:text-white transition-colors"
20+
}
21+
></i>
1622
</Link> :
1723
""
1824
})

frontend/src/components/CommentCard.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ const CommentCard = ({ index, leftVal, commentData }) => {
122122
let btn = (
123123
<button
124124
onClick={() => loadReplies({ skip: index - parentIndex, currentIndex: getParentIndex() })}
125-
className="text-gray-500 p-2 px-3 hover:bg-gray-50 rounded-md flex items-center gap-2">
125+
className="text-[#555] dark:text-gray-300 p-2 px-3 hover:bg-[#f3f3f3] dark:hover:bg-[#1e1e1e] rounded-md flex items-center gap-2"
126+
>
126127
Load More Replies
127128
</button>
128129
);
@@ -159,13 +160,13 @@ const CommentCard = ({ index, leftVal, commentData }) => {
159160
commentData.isReplyLoaded ?
160161
<button
161162
onClick={hideReplies}
162-
className="text-gray-500 p-2 px-3 hover:bg-gray-50 rounded-md flex items-center gap-2"
163+
className="text-[#555] dark:text-gray-300 p-2 px-3 hover:bg-[#f3f3f3] dark:hover:bg-[#1e1e1e] rounded-md flex items-center gap-2"
163164
>
164165
<i className="fi fi-rs-comment-dots"></i> Hide Reply
165166
</button> :
166167
<button
167168
onClick={loadReplies}
168-
className="text-gray-500 p-2 px-3 hover:bg-gray-50 rounded-md flex items-center gap-2"
169+
className="text-[#555] dark:text-gray-300 p-2 px-3 hover:bg-[#f3f3f3] dark:hover:bg-[#1e1e1e] rounded-md flex items-center gap-2"
169170
>
170171
<i className="fi fi-rs-comment-dots"></i> {children.length} Reply
171172
</button>

frontend/src/components/CommentField.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const CommentField = ({ action, index = undefined, replyingTo = undefined, setRe
7070
>
7171
</textarea>
7272
<button
73-
className="btn-dark mt-5 px-10"
73+
className="btn-dark dark:btn-light mt-5 px-10"
7474
onClick={handleComment}
7575
>
7676
{action}

frontend/src/components/Comments.jsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,22 @@ const CommentsContainer = () => {
4141
}
4242

4343
return (
44-
<div className={"max-sm:w-full fixed " + (commentsWrapper ? "top-0 sm:right-0" : "top-[100%] sm:right-[-100%]") + " duration-700 max-sm:right-0 sm:top-0 w-[30%] min-w-[350px] h-full z-50 bg-white shadow-2xl p-8 px-16 overflow-y-auto overflow-x-hidden"}>
44+
<div
45+
className={
46+
"max-sm:w-full fixed " +
47+
(commentsWrapper ? "top-0 sm:right-0" : "top-[100%] sm:right-[-100%]") +
48+
" duration-700 max-sm:right-0 sm:top-0 w-[30%] min-w-[350px] h-full z-50 " +
49+
"bg-white dark:bg-[#121212] shadow-2xl dark:shadow-lg text-black dark:text-gray-200 p-8 px-16 overflow-y-auto overflow-x-hidden"
50+
}
51+
>
4552

4653
<div className="relative">
4754
<h1 className="font-medium text-xl">Comments</h1>
4855
<p className="text-lg mt-2 w-[70%] text-gray-500 line-clamp-1">{title}</p>
4956

5057
<button
5158
onClick={() => setCommentsWrapper(preVal => !preVal)}
52-
className="absolute top-0 right-0 flex justify-center items-center w-12 h-12 rounded-full bg-gray-100"
59+
className="absolute top-0 right-0 flex justify-center items-center w-12 h-12 rounded-full bg-gray-100 dark:bg-[#09090b]"
5360
>
5461
<i className="fi fi-br-cross text-2xl mt-1"></i>
5562
</button>

frontend/src/components/InPageNavigation.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ const InPageNavigation = ({ routes, defaultHidden = [], defaultActiveIndex = 0,
3939

4040
return (
4141
<>
42-
<div className="relative mb-8 bg-white border-b border-gray-200 flex flex-nowrap overflow-x-auto">
42+
<div className="relative mb-8 bg-[#fafafa] dark:bg-[#09090b] border-b border-gray-200 flex flex-nowrap overflow-x-auto">
4343
{
4444
routes.map((route, i) => {
4545
return (
4646
<button
4747
ref={i === defaultActiveIndex ? activeTabRef : null}
4848
key={i}
49-
className={"p-4 px-5 capitalize " + (inPageNavIndex === i ? "text-black " : "text-dark-grey " + (defaultHidden.includes(route) ? "md:hidden" : ""))}
49+
className={"p-4 px-5 capitalize " + (inPageNavIndex === i ? "text-black dark:text-[#ededed] " : "text-dark-grey dark:text-[#a3a3a3] " + (defaultHidden.includes(route) ? "md:hidden" : ""))}
5050
onClick={(e) => { changePageState(e.target, i) }}
5151
>
5252
{route}

frontend/src/components/LoadMoreData.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const LoadMoreDataBtn = ({ state, fetchDataFun, additionalParam }) => {
44
return (
55
<button
66
onClick={() => fetchDataFun({ ...additionalParam, page: state.page + 1 })}
7-
className="text-gray-800 p-2 px-3 hover:bg-gray-50 rounded-md flex items-center gap-2"
7+
className="text-gray-800 dark:text-gray-200 p-2 px-3 rounded-md hover:bg-gray-100 dark:hover:bg-gray-800 flex items-center gap-2 transition-colors"
88
>
99
Load More
1010
</button>

frontend/src/components/Navbar.jsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Link, Outlet, useNavigate } from "react-router-dom";
33
import { UserContext } from "../App";
44
import UserNavigationPanel from "./UserNavigationPanel";
55
import SubscribeModal from "./SubscribeModal";
6+
import ThemeToggle from "./ThemeToggle";
67
import axios from "axios";
78

89
const Navbar = () => {
@@ -58,26 +59,30 @@ const Navbar = () => {
5859
<>
5960
<nav className="navbar z-50">
6061
<Link to="/" className="flex-none w-10">
61-
<img src="/logo.png" alt="" className="w-full" />
62+
<img src="/logo.png" alt="" className="w-full dark:invert" />
6263
</Link>
6364

64-
<div className={"absolute bg-white w-full left-0 top-full mt-0.5 border-b border-gray-200 py-4 px-[5vw] md:border-0 md:relative md:inset-0 md:p-0 md:w-auto " + (searchBoxVisibility ? "show" : "hidden md:block")}
65+
<div
66+
className={"absolute bg-[#fafafa] dark:bg-[#09090b] w-full left-0 top-full mt-0.5 border-b border-gray-200 dark:border-[#27272a] py-4 px-[5vw] md:border-0 md:relative md:inset-0 md:p-0 md:w-auto " +
67+
(searchBoxVisibility ? "show" : "hidden md:block")}
6568
>
6669
<input
6770
type="text"
6871
placeholder="Search"
69-
className="w-full md:w-auto bg-gray-100 p-4 pl-6 pr-[12%] md:pr-6 rounded-full placeholder:text-dark-grey md:pl-12"
72+
className="w-full md:w-auto bg-[#ffffff] dark:bg-[#18181b] p-4 pl-6 pr-[12%] md:pr-6 rounded-full placeholder:text-dark-grey dark:placeholder:text-gray-400 md:pl-12"
7073
onKeyDown={handleSearch}
7174
/>
72-
<i className="fi fi-rr-search absolute right-[10%] md:pointer-events-none md:left-5 top-1/2 -translate-y-1/2 text-xl text-dark-grey"></i>
75+
<i className="fi fi-rr-search absolute right-[10%] md:pointer-events-none md:left-5 top-1/2 -translate-y-1/2 text-xl text-dark-grey dark:text-gray-400"></i>
7376
</div>
7477

7578
<div className="flex items-center gap-3 md:gap-6 ml-auto">
76-
<button className="md:hidden bg-gray-100 w-12 h-12 rounded-full flex items-center justify-center" onClick={() => setSearchBoxVisibility(!searchBoxVisibility)}>
77-
<i className="fi fi-rr-search text-xl"></i>
79+
<button className="md:hidden bg-[#ffffff] dark:bg-[#18181b] w-12 h-12 rounded-full flex items-center justify-center" onClick={() => setSearchBoxVisibility(!searchBoxVisibility)}>
80+
<i className="fi fi-rr-search text-xl text-dark-grey dark:text-gray-400"></i>
7881
</button>
7982

80-
<Link to="/editor" className="hidden md:flex items-center gap-2 text-gray-700 hover:text-black hover:bg-gray-200 p-3 px-4 rounded-lg transition">
83+
<ThemeToggle />
84+
85+
<Link to="/editor" className="hidden md:flex items-center gap-2 text-gray-700 dark:text-gray-300 hover:text-black dark:hover:text-white hover:bg-gray-200 dark:hover:bg-[#27272a] p-3 px-4 rounded-lg transition">
8186
<i className="fi fi-rr-file-edit"></i>
8287
<p>Write</p>
8388
</Link>
@@ -86,7 +91,7 @@ const Navbar = () => {
8691
access_token ?
8792
<>
8893
<Link to="/dashboard/notifications">
89-
<button className="w-12 h-12 rounded-full bg-gray-200 relative hover:bg-black/10">
94+
<button className="w-12 h-12 rounded-full relative text-gray-700 dark:text-gray-300 hover:text-black dark:hover:text-white hover:bg-gray-200 dark:hover:bg-[#27272a]">
9095
<i className="fi fi-rr-bell text-2xl block mt-1"></i>
9196
{
9297
new_notification_available ?
@@ -112,15 +117,15 @@ const Navbar = () => {
112117
<>
113118
<button
114119
onClick={toggleSubscribeModal}
115-
className="text-gray-700 bg-gray-200 py-2 px-4 rounded-full transition cursor-pointer"
120+
className="text-gray-700 dark:text-gray-300 hover:text-black dark:hover:text-white hover:bg-gray-200 dark:hover:bg-[#27272a] py-2 px-4 rounded-full transition cursor-pointer"
116121
>
117122
<i className="fi fi-rr-envelope-plus text-xl"></i>
118123
</button>
119124

120-
<Link className="bg-black text-white py-2 px-5 rounded-full hover:bg-gray-800 transition" to="/login">
125+
<Link className="bg-black dark:bg-gray-200 text-white dark:text-gray-800 py-2 px-5 rounded-full hover:bg-gray-800 dark:hover:bg-[#ffffff] transition" to="/login">
121126
Login
122127
</Link>
123-
<Link className="bg-gray-200 text-gray-800 py-2 px-5 rounded-full hidden md:block hover:bg-gray-300 transition" to="/signup">
128+
<Link className="bg-gray-200 dark:bg-black text-gray-800 dark:text-white py-2 px-5 rounded-full hidden md:block hover:bg-gray-300 dark:hover:bg-[#27272a] transition" to="/signup">
124129
Sign Up
125130
</Link>
126131
</>

frontend/src/components/NoData.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const NoDataMessage = ({ message }) => {
22
return (
3-
<div className="text-center w-full p-4 rounded-full bg-gray-50 mt-4">
3+
<div className="text-center w-full p-4 rounded-full bg-gray-50 dark:bg-[#1a1a1a] text-gray-800 dark:text-gray-200 mt-4">
44
<p>{message}</p>
55
</div>
66
)

frontend/src/components/NotificationCard.jsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ const NotificationCard = ({ data, index, notificationState }) => {
5050
<div className="w-full">
5151
<h1 className="font-medium text-xl text-gray-500">
5252
<span className="lg:inline-block hidden capitalize">{fullname}</span>
53-
<Link to={`/user/${username}`} className="mx-1 text-black underline">@{username}</Link>
53+
<Link
54+
to={`/user/${username}`}
55+
className="mx-1 text-black underline hover:text-blue-600 dark:text-white dark:hover:text-blue-400"
56+
>
57+
@{username}
58+
</Link>
5459
<span className="font-normal">
5560
{
5661
type === 'like' ? "liked your project" :
@@ -62,10 +67,13 @@ const NotificationCard = ({ data, index, notificationState }) => {
6267

6368
{
6469
type === 'reply' ?
65-
<div className="p-4 mt-4 rounded-md bg-gray-100">
70+
<div className="p-4 mt-4 rounded-md bg-gray-100 dark:bg-gray-700">
6671
<p>{replied_on_comment.comment}</p>
6772
</div> :
68-
<Link to={`/project/${project_id}`} className="font-medium text-gray-500 hover:underline line-clamp-1">
73+
<Link
74+
to={`/project/${project_id}`}
75+
className="font-medium text-gray-500 hover:underline line-clamp-1 dark:text-gray-300 dark:hover:text-blue-400"
76+
>
6977
{`"${title}"`}
7078
</Link>
7179
}
@@ -87,7 +95,7 @@ const NotificationCard = ({ data, index, notificationState }) => {
8795
{
8896
!reply ?
8997
<button
90-
className="underline hover:text-black"
98+
className="underline hover:text-black dark:hover:text-white"
9199
onClick={handleReplyClick}
92100
>
93101
Reply
@@ -96,7 +104,7 @@ const NotificationCard = ({ data, index, notificationState }) => {
96104
}
97105

98106
<button
99-
className="underline hover:text-black"
107+
className="underline hover:text-black dark:hover:text-white"
100108
onClick={(e) => handleDelete(comment._id, "comment", e.target)}
101109
>
102110
Delete
@@ -116,25 +124,25 @@ const NotificationCard = ({ data, index, notificationState }) => {
116124

117125
{
118126
reply ?
119-
<div className="ml-20 p-5 bg-gray-100 mt-5 rounded-md">
127+
<div className="ml-20 p-5 bg-gray-100 dark:bg-gray-700 mt-5 rounded-md">
120128
<div className="flex gap-3 mb-3">
121129
<img src={author_profile_img} className="w-8 h-8 rounded-full" alt="" />
122130

123131
<div>
124132
<h1 className="font-medium text-xl text-gray-500">
125-
<Link to={`/user/${author_username}`} className="mx-1 text-black underline">@{author_username}</Link>
133+
<Link to={`/user/${author_username}`} className="mx-1 text-black dark:text-white underline">@{author_username}</Link>
126134

127135
<span className="font-normal">replied to</span>
128136

129-
<Link to={`/user/${username}`} className="mx-1 text-black underline">@{username}</Link>
137+
<Link to={`/user/${username}`} className="mx-1 text-black dark:text-white underline">@{username}</Link>
130138
</h1>
131139
</div>
132140
</div>
133141

134142
<p className="ml-14 font-gelasio text-xl my-2">{reply.comment}</p>
135143

136144
<button
137-
className="underline hover:text-black ml-14 mt-2"
145+
className="underline hover:text-black hover:dark:text-white ml-14 mt-2"
138146
onClick={(e) => handleDelete(reply._id, "reply", e.target)}
139147
>
140148
Delete

frontend/src/components/ProjectEditor.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ const ProjectEditor = () => {
158158
<>
159159
<nav className="navbar">
160160
<Link to="/" className="flex-none w-10">
161-
<img src="logo.png" />
161+
<img src="logo.png" alt="" className="dark:invert" />
162162
</Link>
163-
<p className="max-md:hidden text-black line-clamp-1 w-full">
163+
<p className="max-md:hidden text-black dark:text-white line-clamp-1 w-full">
164164
{title.length ? title : "New Project"}
165165
</p>
166166

0 commit comments

Comments
 (0)