+
-
+
(() => {
return Object.entries(baseNotes)
.map(([, note]) => ({
...note,
- wordCount: note.content.split(' ').filter((word) => word.length > 0).length,
+ wordCount: note.content.split(' ').filter((word) => word.length > 0).length
}))
.sort((a, b) => b.modified - a.modified) as Note[]
})
watch(notes, () => {
- if (notes.value.length > 0 && !activeNote.value) setActiveNote(rootNote.value?.id)
+ if (notes.value.length > 0 && !activeNote.value && activeViewMode.value.name === 'Note')
+ setActiveNote(rootNote.value?.id)
})
const activeNoteId = ref()
-export const activeNote = computed(() =>
- notes.value.find((note) => note.id === activeNoteId.value)
-)
+export const activeNote = computed(() => notes.value.find((note) => note.id === activeNoteId.value))
watch(activeNote, () => {
if (activeNote.value) {
useTitle(`${activeNote.value.title} | Contexted`)
@@ -30,8 +29,7 @@ watch(activeNote, () => {
export const setActiveNote = (noteId: string | undefined) => {
if (noteId) {
activeNoteId.value = noteId
- activeViewMode.value =
- viewModes.find((mode) => mode.name === 'Note') || viewModes[0]
+ activeViewMode.value = viewModes.find((mode) => mode.name === 'Note') || viewModes[0]
}
}
@@ -78,9 +76,7 @@ export const findNotes = (query: string): Note[] => {
}
return notes.value.filter((note) => {
const matchTitle = note.title.toLowerCase().includes(query.toLowerCase())
- const matchContent = removeMdFromText(note.content)
- .toLowerCase()
- .includes(query.toLowerCase())
+ const matchContent = removeMdFromText(note.content).toLowerCase().includes(query.toLowerCase())
return matchTitle || matchContent
})
}
@@ -88,7 +84,7 @@ export const findNotes = (query: string): Note[] => {
export const updateNote = (noteId: string, note: BaseNote) => {
const updatedNote: BaseNote = {
...note,
- modified: new Date().getTime(),
+ modified: new Date().getTime()
}
baseNotes[noteId] = updatedNote
}
@@ -100,7 +96,7 @@ export const addNote = (title: string, content: string, goToNote: boolean = fals
title,
content,
created: new Date().getTime(),
- modified: new Date().getTime(),
+ modified: new Date().getTime()
}
baseNotes[id] = newNote
if (goToNote) setActiveNote(id)
@@ -143,16 +139,14 @@ export const notesRelations = computed(() => {
.map((noteRelations, _, notesRelations): NoteRelations => {
const from = [...notesRelations]
.map((noteRelation) =>
- noteRelation.to
- .filter((toId) => toId === noteRelations.id)
- .map(() => noteRelation.id)
+ noteRelation.to.filter((toId) => toId === noteRelations.id).map(() => noteRelation.id)
)
.reduce((arr, elem) => arr.concat(elem), [])
.filter((value, index, self) => self.indexOf(value) === index)
return {
id: noteRelations.id,
to: noteRelations.to,
- from,
+ from
}
})
.reduce((notes, { id, to, from }) => {
@@ -161,3 +155,14 @@ export const notesRelations = computed(() => {
}, {} as NotesRelations)
return relations
})
+
+export function getNoteReferences(note: Note) {
+ const relations = notesRelations.value[note.id]
+ return relations
+ ? (relations.from || [])
+ .map((noteId) => {
+ return notes.value.find((note) => note.id === noteId)
+ })
+ .filter((note): note is Note => note !== undefined)
+ : []
+}