Skip to content

Commit f0f4d7d

Browse files
fixed emoji picking issue while editing a todo item
1 parent 9625266 commit f0f4d7d

File tree

5 files changed

+48
-40
lines changed

5 files changed

+48
-40
lines changed

components/AllTasks.jsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ export default function AllTasks({ user, todoList, setLoading }) {
7676
return item;
7777
}
7878
});
79+
setUpdates({
80+
title: result[0].title,
81+
status: result[0].status,
82+
isImportant: result[0].isImportant
83+
});
7984
setCurrentItem(result);
8085
};
8186

@@ -90,9 +95,9 @@ export default function AllTasks({ user, todoList, setLoading }) {
9095
};
9196

9297
const onEmojiClick = (emojiObject) => {
93-
setUpdates((prevUpdates) => ({
94-
...prevUpdates,
95-
title: prevUpdates.title + emojiObject.emoji,
98+
setUpdates((currentItem) => ({
99+
...currentItem,
100+
title: currentItem.title + emojiObject.emoji,
96101
}));
97102
setShowEmojiPicker(false);
98103
};
@@ -115,7 +120,7 @@ export default function AllTasks({ user, todoList, setLoading }) {
115120

116121
return (
117122
<>
118-
<ul className=" transition duration-300 ease-out">
123+
<ul className="transition duration-300 ease-out ">
119124
{todoList ? (
120125
todoList.length === 0 ? (
121126
<motion.div
@@ -163,9 +168,9 @@ export default function AllTasks({ user, todoList, setLoading }) {
163168
transition={{ delay: 0.25 }}
164169
>
165170
<div className="flex gap-2">
166-
<div className={`${item.status === "completed" && 'border-gray-600'} relative w-11/12 h-auto p-2 bg-transparent transition ${edit && item.id === currentItem?.[0]?.id ? "border-cyan-400 border-b-2" : "border-cyan-600 border-b"} flex justify-start items-center px-1`}>
171+
<div className={`${item.status === "completed" && 'border-gray-600'} relative min-w-[400px] w-11/12 h-auto p-2 bg-transparent transition ${edit && item.id === currentItem?.[0]?.id ? "border-cyan-400 border-b-2" : "border-cyan-600 border-b"} flex justify-start items-center px-1`}>
167172
<div className="flex items-center gap-1">
168-
{!edit && item.id === currentItem?.[0]?.id} <Popconfirm
173+
{!edit && item.id === currentItem?.[0]?.id} <Popconfirm
169174
title={item.isImportant ? "Mark as not important" : "Mark as important"}
170175
onConfirm={() => handleToggleImportant(item.isImportant, item)}
171176
onCancel={cancel}
@@ -189,7 +194,6 @@ export default function AllTasks({ user, todoList, setLoading }) {
189194
{edit && item.id === currentItem[0].id ? (
190195
<>
191196
<input
192-
defaultValue={item.title}
193197
value={updates.title}
194198
onChange={(e) => {
195199
setUpdates((prevUpdates) => {
@@ -213,14 +217,13 @@ export default function AllTasks({ user, todoList, setLoading }) {
213217
exit={{ opacity: 0 }}
214218
transition={{ delay: 0.50 }}
215219
className="absolute right-6 top-10 z-10" ref={pickerRef}>
216-
<Picker
217-
onEmojiClick={onEmojiClick} />
220+
<Picker onEmojiClick={onEmojiClick} />
218221
</motion.div>
219222
}
220223
</>
221224
) : (
222225
<motion.p
223-
className={`${item.status === "completed" ? 'line-through text-gray-400' : ""} decoration-white decoration-3 text-sm mt-0.5 ml-2 text-gray-300 font-semibold`}
226+
className={`${item.status === "completed" ? 'line-through text-gray-400' : ""} overflow-hidden line-clamp-3 decoration-white decoration-3 text-sm mt-0.5 ml-2 text-gray-300 break-words ... font-semibold`}
224227
initial={{ opacity: 0, y: 5 }}
225228
animate={{ opacity: 1, y: 0 }}
226229
exit={{ opacity: 0, x: 5 }}

helpers/hooks/useAuth.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import { auth } from '../../server/firebase';
22
import { useAuthState } from "react-firebase-hooks/auth";
3+
import Cookies from 'js-cookie';
34

45
const useAuth = () => {
56
const [user, laoding, error] = useAuthState(auth);
7+
if(user){
8+
Cookies.set('token', user.accessToken)
9+
} else [
10+
Cookies.remove('token')
11+
]
612
return user;
713
};
814

src/app/Home/page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export default function Home() {
138138
>
139139
<Header />
140140
<User />
141-
<div className="h-[700px] mt-10 transition-all w-11/12 md:w-3/4 lg:w-2/3 xl:w-2/3 2xl:w-1/2 bg-slate-900 rounded-lg p-10 drop-shadow-md shadow-cyan-800">
141+
<div className="h-[700px] pt-10 transition-all w-full sm:w-11/12 md:w-3/4 lg:w-2/3 xl:w-2/3 2xl:w-1/2 sm:bg-slate-900 rounded-lg p-4 sm:p-10 drop-shadow-md shadow-cyan-800">
142142
<div className="mt-3 text-sm text-white flex justify-between items-center">
143143
<p className=" font-semibold">{currentDate}</p>
144144
<p className=" font-semibold">{currentTime}</p>

src/app/common/header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react'
33
export default function Header() {
44
return (
55
<>
6-
<div className='fixed top-4 left-10'>
6+
<div className='fixed top-4 left-4 sm:left-10'>
77
<p className="text-xl font-semibold mt-6 text-white border-l-8 border-cyan-500 pl-3">
88
TO-DO
99
</p>

src/middleware.js

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
import { NextResponse } from "next/server";
22

3-
// let authToken = Cookies.get("authToken");
4-
53
export default function middleware(request) {
4+
const { cookies } = request;
5+
const authToken = cookies.get("token");
66
const req = request;
7-
8-
// if (req.nextUrl.pathname.startsWith("/Home")) {
9-
// if (authToken) {
10-
// const url = request.nextUrl.clone();
11-
// url.pathname = "/Home";
12-
// return NextResponse.rewrite(url);
13-
// } else {
14-
// return NextResponse.redirect("http://localhost:3000/Login");
15-
// }
16-
// }
17-
// if (req.nextUrl.pathname.startsWith("/Register")) {
18-
// if (authToken) {
19-
// return NextResponse.redirect("http://localhost:3000/Home");
20-
// } else {
21-
// const url = request.nextUrl.clone();
22-
// url.pathname = "/Register";
23-
// return NextResponse.rewrite(url);
24-
// }
25-
// }
26-
// if (
27-
// req.nextUrl.pathname.startsWith("/Login")
28-
// ) {
29-
// if (authToken) {
30-
// return NextResponse.redirect("http://localhost:3000/Home");
31-
// }
32-
// }
7+
if (req.nextUrl.pathname.startsWith("/Home")) {
8+
if (authToken) {
9+
const url = request.nextUrl.clone();
10+
url.pathname = "/Home";
11+
return NextResponse.rewrite(url);
12+
} else {
13+
return NextResponse.redirect("http://localhost:3000/Login");
14+
}
15+
}
16+
if (req.nextUrl.pathname.startsWith("/Register")) {
17+
if (authToken) {
18+
return NextResponse.redirect("http://localhost:3000/Home");
19+
} else {
20+
const url = request.nextUrl.clone();
21+
url.pathname = "/Register";
22+
return NextResponse.rewrite(url);
23+
}
24+
}
25+
if (
26+
req.nextUrl.pathname.startsWith("/Login")
27+
) {
28+
if (authToken) {
29+
return NextResponse.redirect("http://localhost:3000/Home");
30+
}
31+
}
3332
}
3433

3534
export const config = {

0 commit comments

Comments
 (0)