Skip to content

Commit 9fcffc2

Browse files
authored
[431] fix: organize notes in folders in markdown exports (#433)
1 parent 3d99760 commit 9fcffc2

8 files changed

Lines changed: 30 additions & 11 deletions

File tree

lib/common/navigation/enums/notes/selection_available_menu_option.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ enum SelectionAvailableMenuOption {
1717
toggleLock(Icons.lock),
1818

1919
/// Add labels to the notes.
20-
addLabels(Icons.label),
20+
addLabels(Icons.new_label),
2121

2222
/// Archive the notes.
2323
archive(Icons.archive),

lib/models/note/note.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ sealed class Note implements Comparable<Note> {
117117

118118
/// The content as markdown.
119119
@ignore
120-
String get markdown;
120+
String get contentAsMarkdown;
121121

122122
/// The content for the preview of the notes tiles.
123123
@ignore
@@ -155,7 +155,7 @@ sealed class Note implements Comparable<Note> {
155155
@ignore
156156
List<Label> get labelsVisibleSorted => labels.toList().where((label) => label.visible).sorted();
157157

158-
/// Returns the names of the visible [labels] of the note as a sorted list.
158+
/// The names of the visible [labels] of the note as a sorted list.
159159
@ignore
160160
List<String> get labelsNamesVisibleSorted => labelsVisibleSorted.map((label) => label.name).toList();
161161

@@ -167,6 +167,10 @@ sealed class Note implements Comparable<Note> {
167167
@ignore
168168
bool get hasLockedLabel => labels.any((label) => label.locked);
169169

170+
/// The [labels] as markdown.
171+
@ignore
172+
String get labelsAsMarkdown => '> ${labelsNamesVisibleSorted.join(', ')}';
173+
170174
/// Notes are sorted according to:
171175
/// 1. Their pin state.
172176
/// 2. The sort method chosen by the user.

lib/models/note/note_status.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import '../../common/constants/constants.dart';
2+
13
/// The status of a note.
24
enum NoteStatus {
35
/// The note is available.
@@ -7,5 +9,14 @@ enum NoteStatus {
79
archived,
810

911
/// The note is deleted.
10-
deleted,
12+
deleted;
13+
14+
/// Returns the title of this status.
15+
String get title {
16+
return switch (this) {
17+
available => l.navigation_notes,
18+
archived => l.navigation_archives,
19+
deleted => l.navigation_bin,
20+
};
21+
}
1122
}

lib/models/note/types/checklist_note.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class ChecklistNote extends Note {
9393

9494
@ignore
9595
@override
96-
String get markdown {
96+
String get contentAsMarkdown {
9797
StringBuffer plainText = StringBuffer();
9898

9999
for (int index = 0; index < checkboxes.length; index++) {

lib/models/note/types/markdown_note.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class MarkdownNote extends Note {
6767

6868
@ignore
6969
@override
70-
String get markdown => content;
70+
String get contentAsMarkdown => content;
7171

7272
@ignore
7373
@override

lib/models/note/types/plain_text_note.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class PlainTextNote extends Note {
6767

6868
@ignore
6969
@override
70-
String get markdown => content;
70+
String get contentAsMarkdown => content;
7171

7272
@ignore
7373
@override

lib/models/note/types/rich_text_note.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class RichTextNote extends Note {
7474

7575
@ignore
7676
@override
77-
String get markdown => parchmentMarkdownCodec.encode(document);
77+
String get contentAsMarkdown => parchmentMarkdownCodec.encode(document);
7878

7979
@ignore
8080
@override

lib/services/backup/backup_service.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,15 @@ class ManualBackupService {
291291
final archive = Archive();
292292

293293
for (final note in notes) {
294-
final bytes = utf8.encode(note.markdown);
294+
final markdown = '${note.labelsAsMarkdown}\n\n${note.contentAsMarkdown}';
295+
final bytes = utf8.encode(markdown);
295296

296-
final filenameWithoutExtension = '${note.title} (${note.createdTime.filename})';
297+
final filenameWithoutExtension = '${note.title} (${note.createdTime.filename})'.trim();
297298
final filenameWithoutExtensionSanitized = sanitizeFilename(filenameWithoutExtension);
298-
final filename = 'test/$filenameWithoutExtensionSanitized.${MimeType.markdown.extension}';
299+
300+
final folder = note.status.title;
301+
302+
final filename = '$folder/$filenameWithoutExtensionSanitized.${MimeType.markdown.extension}';
299303

300304
archive.addFile(ArchiveFile(filename, bytes.length, bytes));
301305
}

0 commit comments

Comments
 (0)