mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 02:07:39 +08:00
TagsFolder: Auto add relevant tag to new notes
This commit is contained in:
@ -68,10 +68,17 @@ class Note with NotesNotifier {
|
||||
|
||||
Note(this.parent, this._filePath);
|
||||
|
||||
Note.newNote(this.parent) {
|
||||
Note.newNote(this.parent, {Map<String, dynamic> extraProps = const {}}) {
|
||||
created = DateTime.now();
|
||||
_loadState = NoteLoadState.Loaded;
|
||||
_fileFormat = NoteFileFormat.Markdown;
|
||||
|
||||
if (extraProps.isNotEmpty) {
|
||||
extraProps.forEach((key, value) {
|
||||
_data.props[key] = value;
|
||||
});
|
||||
noteSerializer.decode(_data, this);
|
||||
}
|
||||
}
|
||||
|
||||
String get filePath {
|
||||
|
@ -106,9 +106,15 @@ class NoteSerializer implements NoteSerializerInterface {
|
||||
}
|
||||
|
||||
try {
|
||||
var tags = data.props[settings.tagsKey] as YamlList;
|
||||
var tags = data.props[settings.tagsKey];
|
||||
if (tags != null) {
|
||||
note.tags = tags.map((t) => t.toString()).toSet();
|
||||
if (tags is YamlList) {
|
||||
note.tags = tags.map((t) => t.toString()).toSet();
|
||||
} else if (tags is List) {
|
||||
note.tags = tags.map((t) => t.toString()).toSet();
|
||||
} else {
|
||||
Log.e("Note Tags Decoding Failed: $tags");
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
Log.e("Note Decoding Failed: $e");
|
||||
|
@ -28,8 +28,12 @@ enum DropDownChoices {
|
||||
|
||||
class FolderView extends StatefulWidget {
|
||||
final NotesFolder notesFolder;
|
||||
final Map<String, dynamic> newNoteExtraProps;
|
||||
|
||||
FolderView({@required this.notesFolder});
|
||||
FolderView({
|
||||
@required this.notesFolder,
|
||||
this.newNoteExtraProps = const {},
|
||||
});
|
||||
|
||||
@override
|
||||
_FolderViewState createState() => _FolderViewState();
|
||||
@ -211,7 +215,11 @@ class _FolderViewState extends State<FolderView> {
|
||||
var routeType =
|
||||
SettingsEditorType.fromEditorType(editorType).toInternalString();
|
||||
var route = MaterialPageRoute(
|
||||
builder: (context) => NoteEditor.newNote(fsFolder, editorType),
|
||||
builder: (context) => NoteEditor.newNote(
|
||||
fsFolder,
|
||||
editorType,
|
||||
newNoteExtraProps: widget.newNoteExtraProps,
|
||||
),
|
||||
settings: RouteSettings(name: '/newNote/$routeType'),
|
||||
);
|
||||
await Navigator.of(context).push(route);
|
||||
|
@ -29,23 +29,32 @@ class NoteEditor extends StatefulWidget {
|
||||
final String existingText;
|
||||
final List<String> existingImages;
|
||||
|
||||
final Map<String, dynamic> newNoteExtraProps;
|
||||
|
||||
NoteEditor.fromNote(this.note)
|
||||
: notesFolder = note.parent,
|
||||
defaultEditorType = null,
|
||||
existingText = null,
|
||||
existingImages = null;
|
||||
existingImages = null,
|
||||
newNoteExtraProps = null;
|
||||
|
||||
NoteEditor.newNote(
|
||||
this.notesFolder,
|
||||
this.defaultEditorType, {
|
||||
this.existingText,
|
||||
this.existingImages,
|
||||
this.newNoteExtraProps = const {},
|
||||
}) : note = null;
|
||||
|
||||
@override
|
||||
NoteEditorState createState() {
|
||||
if (note == null) {
|
||||
return NoteEditorState.newNote(notesFolder, existingText, existingImages);
|
||||
return NoteEditorState.newNote(
|
||||
notesFolder,
|
||||
existingText,
|
||||
existingImages,
|
||||
newNoteExtraProps,
|
||||
);
|
||||
} else {
|
||||
return NoteEditorState.fromNote(note);
|
||||
}
|
||||
@ -72,8 +81,9 @@ class NoteEditorState extends State<NoteEditor> {
|
||||
NotesFolderFS folder,
|
||||
String existingText,
|
||||
List<String> existingImages,
|
||||
Map<String, dynamic> extraProps,
|
||||
) {
|
||||
note = Note.newNote(folder);
|
||||
note = Note.newNote(folder, extraProps: extraProps);
|
||||
if (existingText != null) {
|
||||
note.body = existingText;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:gitjournal/core/flattened_notes_folder.dart';
|
||||
import 'package:gitjournal/core/note.dart';
|
||||
import 'package:gitjournal/core/note_serializer.dart';
|
||||
import 'package:gitjournal/core/notes_folder_fs.dart';
|
||||
import 'package:gitjournal/screens/folder_view.dart';
|
||||
import 'package:gitjournal/widgets/app_bar_menu_button.dart';
|
||||
@ -52,7 +53,13 @@ class TagListingScreen extends StatelessWidget {
|
||||
title: tag,
|
||||
);
|
||||
|
||||
return FolderView(notesFolder: folder);
|
||||
final propNames = NoteSerializationSettings();
|
||||
return FolderView(
|
||||
notesFolder: folder,
|
||||
newNoteExtraProps: {
|
||||
propNames.tagsKey: [tag],
|
||||
},
|
||||
);
|
||||
},
|
||||
settings: const RouteSettings(name: '/tags/'),
|
||||
);
|
||||
|
Reference in New Issue
Block a user