Skip to content
Merged
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
8 changes: 4 additions & 4 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}
title={note.titlePreview || ''}
desc={note.contentPreview || ''}
atime={note.atime}
/>
</div>
Expand Down
4 changes: 2 additions & 2 deletions components/recents/RecentsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const timeAgo = (timestamp: number): string => {
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-extrabold text-sm line-clamp-1 break-all overflow-ellipsis'>{title}</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
7 changes: 6 additions & 1 deletion lib/controller/NoteController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export type Note = {
atime : number
mtime : number
snippetContent? : string
contentPreview? : string
titlePreview? : string
}

// NoteController manages notes in the database.
Expand Down Expand Up @@ -60,9 +62,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, 150) AS contentPreview,
SUBSTR(title,1,50) AS titlePreview FROM Notes ORDER BY atime DESC LIMIT ?;`
return await this.select<Note>(query, [count])
}

Expand Down