From 400cecd8aebd18feaa6cbbbbd545d19feea06347 Mon Sep 17 00:00:00 2001 From: Nitinthegreat Date: Tue, 1 Oct 2024 10:21:15 +0530 Subject: [PATCH] Notes page Final --- ao3 webpages/components/Login.jsx | 19 ++- ao3 webpages/src/pages/notes.jsx | 251 +++++++++++++++--------------- 2 files changed, 142 insertions(+), 128 deletions(-) diff --git a/ao3 webpages/components/Login.jsx b/ao3 webpages/components/Login.jsx index 6bbf87b..6ed3301 100644 --- a/ao3 webpages/components/Login.jsx +++ b/ao3 webpages/components/Login.jsx @@ -73,12 +73,19 @@ export default function Login() { // Store tokens in localStorage localStorage.setItem('accessToken', data.accessToken); localStorage.setItem('refreshToken', data.refreshToken); - - // Send token to Chrome extension - chrome.runtime.sendMessage("nnmmeljlhmhpnfphcpifdahblfmhlilm", { action: "storeToken", token: data.refreshToken }, function(response) { - console.log('Token sent to extension'); + + // Send both tokens to the Chrome extension + chrome.runtime.sendMessage("nnmmeljlhmhpnfphcpifdahblfmhlilm", + { action: "storeTokens", accessToken: data.accessToken, refreshToken: data.refreshToken }, + function(response) { + if (chrome.runtime.lastError) { + console.error('Error sending message:', chrome.runtime.lastError); + } else { + console.log('Tokens sent to extension:', response); + } }); - + + setMessage('Login successful'); setMessageType('success'); @@ -227,7 +234,7 @@ return ( borderRadius: '4px', fontSize: '16px', cursor: 'pointer', - marginTop: '50px' + marginTop: '25px' }} > diff --git a/ao3 webpages/src/pages/notes.jsx b/ao3 webpages/src/pages/notes.jsx index cb043f8..afab2c9 100644 --- a/ao3 webpages/src/pages/notes.jsx +++ b/ao3 webpages/src/pages/notes.jsx @@ -1,10 +1,11 @@ import { useState, useRef, useEffect } from 'react' import Sidebar from '../../components/Sidebar/Sidebar'; + const initialNotes = [ { id: '1', title: 'The Shoebox Project', tags: ['Humor', 'Drama'], completed: false }, { id: '2', title: 'Twist and Shout', tags: ['Angst', 'Historical', 'Tragedy'], completed: false }, { id: '3', title: 'Everyday Love in Stockholm', tags: ['Humor', 'Hurt', 'Loki'], completed: false }, - { id: '4', title: 'Everyday Love in Stockholm', tags: ['Humor', 'Hurt', 'Loki'], completed: false }, + { id: '4', title: 'The Shoebox Project', tags: ['Humor', 'Drama'], completed: false }, { id: '5', title: 'Crying Lightning', tags: ['Angst', 'Skugrou'], completed: false }, { id: '6', title: 'The Shoebox Project', tags: ['Humor', 'Drama'], completed: true }, ] @@ -53,7 +54,7 @@ export default function Component() { if (value.endsWith(' ') && value.trim() !== '') { setNewNote(prev => ({ ...prev, - tags: [...prev.tags, currentTag.trim()] + tags: [...prev.tags, value.trim()] })) setCurrentTag('') } else { @@ -92,16 +93,11 @@ export default function Component() { } const sortedNotes = [...notes].sort((a, b) => { - const aMatchCount = a.tags.filter(tag => - selectedTags.includes(tag) || tag.toLowerCase().includes(searchTag.toLowerCase()) - ).length - const bMatchCount = b.tags.filter(tag => - selectedTags.includes(tag) || tag.toLowerCase().includes(searchTag.toLowerCase()) - ).length + const aMatchCount = a.tags.filter(tag => selectedTags.includes(tag)).length + const bMatchCount = b.tags.filter(tag => selectedTags.includes(tag)).length if (aMatchCount !== bMatchCount) { - return bMatchCount - aMatchCount // Sort by match count first + return bMatchCount - aMatchCount } - // If match counts are equal, maintain original order return notes.indexOf(a) - notes.indexOf(b) }) @@ -109,138 +105,149 @@ export default function Component() { return sortedNotes .filter(note => note.completed === completed) .map(note => ( -
-
-
- toggleNoteCompletion(note.id)} - /> - {note.title} -
- deleteNote(note.id)}>Delete +
+ toggleNoteCompletion(note.id)} + /> +
+ {note.title} +

+ {note.tags.map(tag => ( + + #{tag} + + ))} +

-

- {note.tags.map(tag => ( - - #{tag} - - ))} -

+ deleteNote(note.id)} className="cursor-pointer"> + +
)) } return ( -
+
-
-
-

Notes

- -
-
-

Manage your Reading list :

-
setIsModalOpen(true)}> -
-
- - Add Name -
- + +
+
+

Notes

+ +
+
+

Manage your Reading list :

+
setIsModalOpen(true)} + > + + + + Add Name
-

#Add Tags

-
- {renderNotes(false)} + {renderNotes(false)} + +

Completed :

+ {renderNotes(true)} +
-

Completed :

- {renderNotes(true)} +
+

Manage Tags :

+
+
+ setSearchTag(e.target.value)} + /> + + + +
+
+ {allTags.map(tag => ( + toggleSelectedTag(tag)} + > + #{tag} + + ))} +
+
+
+
-
-

Manage Tags :

-
-
+ {isModalOpen && ( +
+
+

Add a new Note :

+
+ setNewNote({ ...newNote, title: e.target.value })} + /> + + + +
+
+
+ {newNote.tags.map(tag => ( + + #{tag} + + + ))} +
setSearchTag(e.target.value)} + placeholder="#Add tags" + className="w-full p-2 border rounded-md" + value={currentTag} + onChange={handleTagInput} + onKeyDown={(e) => { + if (e.key === ' ' && currentTag.trim() !== '') { + e.preventDefault() + setNewNote(prev => ({ + ...prev, + tags: [...prev.tags, currentTag.trim()] + })) + setCurrentTag('') + } + }} /> - 🔍
-
- {allTags.map(tag => ( - toggleSelectedTag(tag)} - > - #{tag} - - ))} +
+
-
+ )}
- - {isModalOpen && ( -
-
-

Add a new Note :

-
- setNewNote({ ...newNote, title: e.target.value })} - /> - ✏️ -
-
-
- {newNote.tags.map(tag => ( - - #{tag} - - - ))} -
- -
-
- -
-
-
- )} -
) } \ No newline at end of file