2 Commits

2 changed files with 76 additions and 49 deletions

View File

@@ -507,8 +507,10 @@ class MainPageState extends State<MainPage> with WindowListener {
// Save the current note content before navigating away // Save the current note content before navigating away
if (_currentlyDisplayedNote != null) { if (_currentlyDisplayedNote != null) {
_currentlyDisplayedNote!.content = _previousEntryController.text; if (_currentlyDisplayedNote!.content != _previousEntryController.text) {
await updateNote(_currentlyDisplayedNote!); _currentlyDisplayedNote!.content = _previousEntryController.text;
await updateNote(_currentlyDisplayedNote!);
}
} }
final prevNote = await getPreviousTo(_currentlyDisplayedNote!.epochTime); final prevNote = await getPreviousTo(_currentlyDisplayedNote!.epochTime);
@@ -526,8 +528,10 @@ class MainPageState extends State<MainPage> with WindowListener {
// Save the current note content before navigating away // Save the current note content before navigating away
if (_currentlyDisplayedNote != null) { if (_currentlyDisplayedNote != null) {
_currentlyDisplayedNote!.content = _previousEntryController.text; if (_currentlyDisplayedNote!.content != _previousEntryController.text) {
await updateNote(_currentlyDisplayedNote!); _currentlyDisplayedNote!.content = _previousEntryController.text;
await updateNote(_currentlyDisplayedNote!);
}
} }
final nextNote = await getNextTo(_currentlyDisplayedNote!.epochTime); final nextNote = await getNextTo(_currentlyDisplayedNote!.epochTime);
@@ -593,13 +597,17 @@ class MainPageState extends State<MainPage> with WindowListener {
_currentEntryController.clear(); // Clear the input field after saving _currentEntryController.clear(); // Clear the input field after saving
} }
// Handle scratch pad if (scratchContent != _scratchController.text) {
await createScratch(scratchContent); // Was modified
await createScratch(scratchContent);
}
// Handle previous/currently displayed note // Handle previous/currently displayed note
if (_currentlyDisplayedNote != null) { if (_currentlyDisplayedNote != null) {
_currentlyDisplayedNote!.content = previousEntry; if (_currentlyDisplayedNote!.content != previousEntry) {
await updateNote(_currentlyDisplayedNote!); _currentlyDisplayedNote!.content = previousEntry;
await updateNote(_currentlyDisplayedNote!);
}
// If the note was deleted (due to being empty), update the UI state // If the note was deleted (due to being empty), update the UI state
if (previousEntry.isEmpty) { if (previousEntry.isEmpty) {
@@ -662,9 +670,7 @@ class MainPageState extends State<MainPage> with WindowListener {
spans.add( spans.add(
TextSpan( TextSpan(
text: highlightedText.substring(lastIndex, match.start), text: highlightedText.substring(lastIndex, match.start),
style: const TextStyle( style: const TextStyle(fontSize: 13),
fontSize: 13,
),
), ),
); );
} }
@@ -825,11 +831,18 @@ class MainPageState extends State<MainPage> with WindowListener {
// Save current note if needed // Save current note if needed
if (_currentlyDisplayedNote != if (_currentlyDisplayedNote !=
null) { null) {
_currentlyDisplayedNote!.content = if (_currentlyDisplayedNote!
_previousEntryController.text; .content !=
await updateNote( _previousEntryController
_currentlyDisplayedNote!, .text) {
); _currentlyDisplayedNote!
.content =
_previousEntryController
.text;
await updateNote(
_currentlyDisplayedNote!,
);
}
} }
// Navigate to the selected note // Navigate to the selected note
@@ -1107,19 +1120,23 @@ class MainPageState extends State<MainPage> with WindowListener {
String? errorMessage; String? errorMessage;
// Load current values // Load current values
getMeilisearchEndpoint().then((value) { getMeilisearchEndpoint()
endpointController.text = value; .then((value) {
isLoading = false; endpointController.text = value;
}).catchError((e) { isLoading = false;
errorMessage = 'Failed to load endpoint: $e'; })
isLoading = false; .catchError((e) {
}); errorMessage = 'Failed to load endpoint: $e';
isLoading = false;
});
getMeilisearchApiKey().then((value) { getMeilisearchApiKey()
apiKeyController.text = value; .then((value) {
}).catchError((e) { apiKeyController.text = value;
errorMessage = 'Failed to load API key: $e'; })
}); .catchError((e) {
errorMessage = 'Failed to load API key: $e';
});
showDialog( showDialog(
context: context, context: context,
@@ -1168,29 +1185,34 @@ class MainPageState extends State<MainPage> with WindowListener {
child: const Text('Cancel'), child: const Text('Cancel'),
), ),
TextButton( TextButton(
onPressed: isLoading ? null : () async { onPressed:
try { isLoading
setState(() { ? null
isLoading = true; : () async {
errorMessage = null; try {
}); setState(() {
isLoading = true;
errorMessage = null;
});
await setMeilisearchEndpoint(endpointController.text); await setMeilisearchEndpoint(
await setMeilisearchApiKey(apiKeyController.text); endpointController.text,
);
await setMeilisearchApiKey(apiKeyController.text);
// Try to reinitialize Meilisearch with new settings // Try to reinitialize Meilisearch with new settings
await init(); await init();
if (mounted) { if (mounted) {
Navigator.of(context).pop(); Navigator.of(context).pop();
} }
} catch (e) { } catch (e) {
setState(() { setState(() {
errorMessage = 'Failed to save settings: $e'; errorMessage = 'Failed to save settings: $e';
isLoading = false; isLoading = false;
}); });
} }
}, },
child: const Text('Save'), child: const Text('Save'),
), ),
], ],

View File

@@ -350,6 +350,7 @@ Future<Note> createNote(String content) async {
final document = { final document = {
'id': generateRandomString(32), 'id': generateRandomString(32),
'date': DateTime.now().toUtc().millisecondsSinceEpoch, 'date': DateTime.now().toUtc().millisecondsSinceEpoch,
'dateISO': DateTime.now().toUtc().toIso8601String(),
'content': content, 'content': content,
'topLetter': mostFrequentLetter, 'topLetter': mostFrequentLetter,
'topLetterFrequency': mostFrequentLetterCount, 'topLetterFrequency': mostFrequentLetterCount,
@@ -433,6 +434,10 @@ Future<void> updateNote(Note note) async {
'id': note.id, 'id': note.id,
'content': trimmedContent, 'content': trimmedContent,
'date': note.epochTime, 'date': note.epochTime,
'dateISO':
DateTime.fromMillisecondsSinceEpoch(
note.epochTime,
).toUtc().toIso8601String(),
'topLetter': mostFrequentLetter, 'topLetter': mostFrequentLetter,
'topLetterFrequency': mostFrequentLetterRatio, 'topLetterFrequency': mostFrequentLetterRatio,
}; };