Skip to content

Commit

Permalink
refactor: Add note detail view and edit functionality to Card.js
Browse files Browse the repository at this point in the history
  • Loading branch information
amit712singhal committed Oct 24, 2024
1 parent 61add00 commit 70c26ad
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/js/components/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

import { Tooltip } from "./Tooltip.js";
import { getRelativeTime } from "../utils.js";
import { NoteModal } from "./Modal.js";
import { db } from "../db.js";
import { client } from "../client.js";

/**
* @param {Object} noteData
Expand Down Expand Up @@ -41,5 +44,22 @@ export const Card = function ( noteData )

Tooltip( $card.querySelector( '[data-tooltip]' ) );

/**
* Note detail view & edit functionality
*/
$card.addEventListener( 'click', function ()
{
const /** {Object} */ modal = NoteModal( title, text, getRelativeTime( postedOn ) );
modal.open();
modal.onSubmit( function ( noteData )
{
const updatedData = db.update.note( id, noteData );

// Update note in UI
client.note.update( id, updatedData );
modal.close();
})
} );

return $card;
}

0 comments on commit 70c26ad

Please sign in to comment.