Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions components/recents/Recents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default function Recents() {

// fetchData reads all notes.
const fetchData = async () => {
try { setRecentsData(await db.notes.readAll()) }
try { setRecentsData(await db.notes.getRecents(cardCount)) }
catch (error) {
let description = 'An unknown error has occurred'
if (error instanceof Error) {
Expand All @@ -67,12 +67,12 @@ export default function Recents() {
if (recentsData && recentsData.length > 0) {
const recentsCardsList = recentsData.slice(0, cardCount).map((note, i) => (
<div key={i}
onClick={() => router.push(`/note?id=${note.id}`) }
onClick={() => router.push(`/note?id=${note.id}`) }
className="opacity-0 animate-fade-in"
style={{ animationDelay: `${i * 0.06}s` }}>
<RecentsCard
title={note.title}
desc={note.content}
desc={note.contentPreview || ''}
atime={note.atime}
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion components/recents/RecentsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const RecentsCard = ({title, desc, atime} : RecentsCardsProps) => (
<div className='w-[344px] h-[77px] bg-white rounded-md border border-[#979797] grid grid-cols-[3fr_1fr] my-1'>
<div className="p-2">
<p className='font-extrabold text-sm line-clamp-1'>{title}</p>
<p className='font-light text-sm line-clamp-2'>{desc}</p>
<p className='font-light text-sm line-clamp-2 break-all overflow-ellipsis'>{desc}</p>
</div>
<div className='flex items-center justify-center'>
<p className='text-sm font-light'>{timeAgo(atime)}</p>
Expand Down
6 changes: 5 additions & 1 deletion lib/controller/NoteController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type Note = {
atime : number
mtime : number
snippetContent? : string
contentPreview? : string
}

// NoteController manages notes in the database.
Expand Down Expand Up @@ -60,9 +61,12 @@ class NoteController extends Database {
return await this.select<Note>(`SELECT * FROM Notes;`)
}

// Gets notes to load into recents menu.
// Count should be number of cards that can fit on screen.
async getRecents(count: number) : Promise<Note[]> {
await this.ensureConnected()
const query = `SELECT * FROM Notes ORDER BY atime DESC LIMIT ?;`
const query = `SELECT id, title, atime, SUBSTR(content, 1, 65) AS contentPreview
FROM Notes ORDER BY atime DESC LIMIT ?;`
return await this.select<Note>(query, [count])
}

Expand Down