2 Commits

2 changed files with 76 additions and 49 deletions

View File

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

View File

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