Skip to content
This repository was archived by the owner on Oct 1, 2025. It is now read-only.

Commit d0d05c3

Browse files
committed
test: snapshot of the note update handler implementation
1 parent 72faaf7 commit d0d05c3

File tree

14 files changed

+263
-65
lines changed

14 files changed

+263
-65
lines changed

package-lock.json

Lines changed: 62 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@ralvarezdev/js-logger": "^0.1.13",
1717
"@ralvarezdev/js-mode": "^0.1.9",
1818
"bcryptjs": "^3.0.2",
19+
"buffer": "^6.0.3",
1920
"dotenv": "^16.4.7",
2021
"react": "^18.3.1",
2122
"react-dom": "^18.3.1",

src/App.jsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ import {
2424
import ErrorBoundary from "./components/ErrorBoundary/ErrorBoundary.jsx";
2525
import {
2626
get2FAMethods,
27-
getIsLoggingIn,
27+
getIsLoggingIn, getPassword, setDecryptedKey,
2828
} from "./sessionStorage/sessionStorage.js";
2929
import {useNotes} from "./context/Notes.jsx";
3030
import {useTags} from "./context/Tags.jsx";
3131
import {onDashboardLoad} from "./utils/init.js";
32-
import {getUserIDFromCookie} from "./utils/cookies.js";
32+
import {getEncryptedKey, getSalt, getUserID} from "./utils/cookies.js";
33+
import {getDecryptedKey} from "./utils/crypto.js";
3334

3435
// Authentication endpoints
3536
const NO_AUTH_ENABLED_ENDPOINTS = [LOG_IN, SIGN_UP, FORGOT_PASSWORD, RESET_PASSWORD, VERIFY_EMAIL]
@@ -40,6 +41,7 @@ export default function App() {
4041
const {isAuth} = useAuth();
4142
const path = window.location.pathname;
4243
const [databaseLoaded, setDatabaseLoaded] = useState(false);
44+
const [keyLoaded, setKeyLoaded] = useState(false);
4345
const {loadTagsFromIndexedDB} = useTags();
4446
const {loadNotesFromIndexedDB} = useNotes();
4547

@@ -59,13 +61,24 @@ export default function App() {
5961
// Check if the database has been loaded
6062
if (!databaseLoaded) {
6163
// Get the user ID from cookies
62-
const userID = getUserIDFromCookie()
64+
const userID = getUserID()
6365

6466
// Load database
6567
setDatabaseLoaded(true)
6668
onDashboardLoad(userID, null, null, loadTagsFromIndexedDB, loadNotesFromIndexedDB).then()
6769
}
6870

71+
// Check if the user key has been loaded
72+
if (!keyLoaded) {
73+
// Get the decrypted key
74+
getDecryptedKey(getPassword(), getSalt(), getEncryptedKey()).then(
75+
key => setDecryptedKey(key)
76+
)
77+
78+
// Load the key
79+
setKeyLoaded(true)
80+
}
81+
6982
if (AUTH_DISABLED_ENDPOINTS.includes(parsedPath))
7083
window.location.href = DASHBOARD;
7184
return;

src/components/Note/Note.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import CircularSmallIconButton from "../Button/Circular/Icon/Small/Small.jsx";
44
import {useCallback} from "react";
55
import TransparentSmallIconButton
66
from "../Button/Transparent/Icon/Small/Small.jsx";
7+
import Separator from "../Separator/Separator.jsx";
78

89
// Note component
910
export default function Note({
@@ -63,8 +64,9 @@ export default function Note({
6364
</TransparentSmallIconButton>
6465
</div>
6566
</div>
67+
<Separator/>
6668
<div className='note__main-container__content'>
67-
{children}
69+
<ParagraphText>{children}</ParagraphText>
6870
</div>
6971
</div>
7072
)

src/components/Separator/Separator.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
@media (prefers-color-scheme: light) {
99
.separator {
10-
background-color: var(--color-medium-grey);
10+
background-color: var(--color-dark-grey);
1111
}
1212
}
1313

1414
@media (prefers-color-scheme: dark) {
1515
.separator {
16-
background-color: var(--color-medium-grey);
16+
background-color: var(--color-light-grey);
1717
}
1818
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import './TextArea.css'
22

33
// Text area component
4-
export default function TextArea({resize='none'}) {
4+
export default function TextArea({resize='none', ...props}) {
55
return (
66
<div className='text-area__main-container'>
7-
<textarea className='text-area__main-container__area' style={{resize}}/>
7+
<textarea className='text-area__main-container__area' style={{resize}} {...props}/>
88
</div>
99
)
1010
}

src/context/Auth.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {createContext, useContext, useState} from 'react';
2-
import cookieExists, {getUserIDFromCookie} from "../utils/cookies.js";
2+
import cookieExists, {getUserID} from "../utils/cookies.js";
33
import LOGGER from "../logger.js";
44
import {onLogOut} from "../utils/init.js";
55
import {useTags} from "./Tags.jsx";
@@ -40,7 +40,7 @@ export function AuthProvider({children}) {
4040
onLogOut(clearTags, clearNotes).then()
4141
} else {
4242
// Get the user ID from cookies
43-
const userID = getUserIDFromCookie()
43+
const userID = getUserID()
4444
if (!userID && import.meta.env.IS_DEBUG) LOGGER.error("User ID not found in the cookie")
4545
else if (import.meta.env.IS_DEBUG) LOGGER.info(`User ID found in the cookie: ${userID}`)
4646

src/context/Notes.jsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import {
1212
} from "../indexedDB/transactions.js";
1313
import {db} from "../indexedDB/init.js";
1414
import logger from "../logger.js";
15-
import {encryptNoteVersionContent} from "../utils/crypto.js";
15+
import {
16+
decryptNoteVersionContent,
17+
encryptNoteVersionContent
18+
} from "../utils/crypto.js";
19+
import {getDecryptedKey} from "../sessionStorage/sessionStorage.js";
1620

1721
// Create a context
1822
const NotesContext = createContext(null);
@@ -161,7 +165,7 @@ export function NotesProvider({children}) {
161165
// Alter the IndexedDB
162166
if (alterIndexedDB) {
163167
// Encrypt the note version content
164-
noteVersion.encrypted_content = await encryptNoteVersionContent(noteVersion.encrypted_content);
168+
noteVersion.encrypted_content = await encryptNoteVersionContent(getDecryptedKey(),noteVersion.content);
165169

166170
await UpsertUserNoteVersion(db, noteVersion);
167171
}
@@ -223,7 +227,7 @@ export function NotesProvider({children}) {
223227
if (alterIndexedDB)
224228
for (const noteVersion of noteVersions) {
225229
// Encrypt the note version content
226-
noteVersion.encrypted_content = await encryptNoteVersionContent(noteVersion.encrypted_content);
230+
noteVersion.encrypted_content = await encryptNoteVersionContent(getDecryptedKey(),noteVersion.content);
227231

228232
await UpsertUserNoteVersion(db, noteVersion);
229233
}
@@ -258,6 +262,16 @@ export function NotesProvider({children}) {
258262
return latestNoteVersion;
259263
}, null);
260264
}, [noteVersionsByNoteID]);
265+
266+
// Get latest note version ID
267+
const getLatestNoteVersionID = useCallback(() => {
268+
return Object.keys(noteVersionsByNoteID).reduce((latestNoteVersion, noteID) => {
269+
const noteVersion = getLatestNoteVersionByNoteID(noteID);
270+
if (!latestNoteVersion || noteVersion.created_at > latestNoteVersion.created_at)
271+
return noteVersion;
272+
return latestNoteVersion;
273+
}, null)?.id;
274+
}, [getLatestNoteVersionByNoteID, noteVersionsByNoteID]);
261275

262276
// Clear all note versions
263277
const clearNoteVersions = useCallback(() => {
@@ -273,9 +287,8 @@ export function NotesProvider({children}) {
273287
const noteVersions = await ReadAllUserNoteVersions(db);
274288

275289
// Decrypt the note version content
276-
for (const noteVersion of noteVersions) {
277-
noteVersion.content = await encryptNoteVersionContent(noteVersion.encrypted_content);
278-
}
290+
for (const noteVersion of noteVersions)
291+
noteVersion.content = await decryptNoteVersionContent(getDecryptedKey(), noteVersion.encrypted_content);
279292

280293
await upsertNoteVersions(noteVersions, false);
281294
}, [upsertNoteVersions, clearNoteVersions]);
@@ -422,6 +435,7 @@ export function NotesProvider({children}) {
422435
removeNoteVersionByNoteIDAndID,
423436
getNoteVersionByNoteIDAndID,
424437
getLatestNoteVersionByNoteID,
438+
getLatestNoteVersionID,
425439
clearNoteVersions,
426440
loadNoteVersionsFromIndexedDB,
427441
noteTagsByNoteID,

src/pages/Dashboard/Dashboard.css

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
gap: 1px;
1212
height: 100vh;
1313
width: 100vw;
14+
overflow-x: hidden;
1415
}
1516

1617
/* Menu container styles */
@@ -44,6 +45,7 @@
4445
}
4546

4647
/* Buttons container styles */
48+
.dashboard__note-update-modal__buttons-container,
4749
.dashboard__note-deletion-modal__buttons-container {
4850
display: flex;
4951
align-items: center;
@@ -94,7 +96,7 @@
9496
gap: 1.6rem;
9597
}
9698

97-
/* Header buttons styles */
99+
/* Header button styles */
98100
.dashboard__main-container__menu-container__header-container__header__button,
99101
.dashboard__main-container__notes-container__header-container__header__button,
100102
.dashboard__main-container__note-container__header-container__header__button {
@@ -127,7 +129,6 @@
127129
width: 100%;
128130
max-width: 100%;
129131
max-height: 100%;
130-
animation: appear-and-move-a-bit-up var(--animation-move-duration) ease-in-out forwards;
131132
}
132133

133134
.dashboard__main-container__note-container__content-container {
@@ -154,15 +155,15 @@
154155
color: var(--color-dark-error);
155156
scale: 1.25;
156157

157-
outline: var(--border-width) solid var(--color-dark-error);
158+
border: var(--border-width) solid var(--color-dark-error);
158159
}
159160

160161
/* Dashboard note modals styles */
161162
.dashboard__note-view-modal,
162163
.dashboard__note-creation-modal,
163164
.dashboard__note-deletion-modal {
164-
transition: outline-color var(--color-transition-duration) ease-in-out;
165-
outline: var(--outline-width) solid transparent;
165+
transition: border-color var(--color-transition-duration) ease-in-out;
166+
border: var(--border-width) solid transparent;
166167
}
167168

168169

@@ -234,4 +235,14 @@
234235
.dashboard__main-container__notes-container__content-container {
235236
padding: 1rem 2rem;
236237
}
238+
}
239+
240+
@media (max-width: 600px) {
241+
.dashboard__note-creation-modal,
242+
.dashboard__note-deletion-modal,
243+
.dashboard__note-view-modal,
244+
.dashboard__note-update-modal{
245+
border-right-color: transparent !important;
246+
border-left-color: transparent !important;
247+
}
237248
}

0 commit comments

Comments
 (0)