Compare commits
3 Commits
29f6f28f12
...
v4.2.1
Author | SHA1 | Date | |
---|---|---|---|
df93602db4 | |||
d6f9fa5032 | |||
64884cbb42 |
120
lib/main.dart
120
lib/main.dart
@@ -507,8 +507,10 @@ class MainPageState extends State<MainPage> with WindowListener {
|
||||
|
||||
// Save the current note content before navigating away
|
||||
if (_currentlyDisplayedNote != null) {
|
||||
_currentlyDisplayedNote!.content = _previousEntryController.text;
|
||||
await updateNote(_currentlyDisplayedNote!);
|
||||
if (_currentlyDisplayedNote!.content != _previousEntryController.text) {
|
||||
_currentlyDisplayedNote!.content = _previousEntryController.text;
|
||||
await updateNote(_currentlyDisplayedNote!);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
if (_currentlyDisplayedNote != null) {
|
||||
_currentlyDisplayedNote!.content = _previousEntryController.text;
|
||||
await updateNote(_currentlyDisplayedNote!);
|
||||
if (_currentlyDisplayedNote!.content != _previousEntryController.text) {
|
||||
_currentlyDisplayedNote!.content = _previousEntryController.text;
|
||||
await updateNote(_currentlyDisplayedNote!);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// Handle scratch pad
|
||||
await createScratch(scratchContent);
|
||||
if (scratchContent != _scratchController.text) {
|
||||
// Was modified
|
||||
await createScratch(scratchContent);
|
||||
}
|
||||
|
||||
// Handle previous/currently displayed note
|
||||
if (_currentlyDisplayedNote != null) {
|
||||
_currentlyDisplayedNote!.content = previousEntry;
|
||||
await updateNote(_currentlyDisplayedNote!);
|
||||
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,11 +831,18 @@ class MainPageState extends State<MainPage> with WindowListener {
|
||||
// Save current note if needed
|
||||
if (_currentlyDisplayedNote !=
|
||||
null) {
|
||||
_currentlyDisplayedNote!.content =
|
||||
_previousEntryController.text;
|
||||
await updateNote(
|
||||
_currentlyDisplayedNote!,
|
||||
);
|
||||
if (_currentlyDisplayedNote!
|
||||
.content !=
|
||||
_previousEntryController
|
||||
.text) {
|
||||
_currentlyDisplayedNote!
|
||||
.content =
|
||||
_previousEntryController
|
||||
.text;
|
||||
await updateNote(
|
||||
_currentlyDisplayedNote!,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Navigate to the selected note
|
||||
@@ -1107,19 +1120,23 @@ class MainPageState extends State<MainPage> with WindowListener {
|
||||
String? errorMessage;
|
||||
|
||||
// Load current values
|
||||
getMeilisearchEndpoint().then((value) {
|
||||
endpointController.text = value;
|
||||
isLoading = false;
|
||||
}).catchError((e) {
|
||||
errorMessage = 'Failed to load endpoint: $e';
|
||||
isLoading = false;
|
||||
});
|
||||
getMeilisearchEndpoint()
|
||||
.then((value) {
|
||||
endpointController.text = value;
|
||||
isLoading = false;
|
||||
})
|
||||
.catchError((e) {
|
||||
errorMessage = 'Failed to load endpoint: $e';
|
||||
isLoading = false;
|
||||
});
|
||||
|
||||
getMeilisearchApiKey().then((value) {
|
||||
apiKeyController.text = value;
|
||||
}).catchError((e) {
|
||||
errorMessage = 'Failed to load API key: $e';
|
||||
});
|
||||
getMeilisearchApiKey()
|
||||
.then((value) {
|
||||
apiKeyController.text = value;
|
||||
})
|
||||
.catchError((e) {
|
||||
errorMessage = 'Failed to load API key: $e';
|
||||
});
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
@@ -1168,29 +1185,34 @@ class MainPageState extends State<MainPage> with WindowListener {
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: isLoading ? null : () async {
|
||||
try {
|
||||
setState(() {
|
||||
isLoading = true;
|
||||
errorMessage = null;
|
||||
});
|
||||
onPressed:
|
||||
isLoading
|
||||
? null
|
||||
: () async {
|
||||
try {
|
||||
setState(() {
|
||||
isLoading = true;
|
||||
errorMessage = null;
|
||||
});
|
||||
|
||||
await setMeilisearchEndpoint(endpointController.text);
|
||||
await setMeilisearchApiKey(apiKeyController.text);
|
||||
await setMeilisearchEndpoint(
|
||||
endpointController.text,
|
||||
);
|
||||
await setMeilisearchApiKey(apiKeyController.text);
|
||||
|
||||
// Try to reinitialize Meilisearch with new settings
|
||||
await init();
|
||||
|
||||
if (mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
errorMessage = 'Failed to save settings: $e';
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
// Try to reinitialize Meilisearch with new settings
|
||||
await init();
|
||||
|
||||
if (mounted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
errorMessage = 'Failed to save settings: $e';
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
child: const Text('Save'),
|
||||
),
|
||||
],
|
||||
|
@@ -345,11 +345,13 @@ Future<Note> createNote(String content) async {
|
||||
|
||||
final mostFrequentLetter =
|
||||
letterFrequency.entries.reduce((a, b) => a.value > b.value ? a : b).key;
|
||||
final mostFrequentLetterCount = letterFrequency[mostFrequentLetter];
|
||||
final mostFrequentLetterCount =
|
||||
letterFrequency[mostFrequentLetter]! / trimmedContent.length;
|
||||
|
||||
final document = {
|
||||
'id': generateRandomString(32),
|
||||
'date': DateTime.now().toUtc().millisecondsSinceEpoch,
|
||||
'dateISO': DateTime.now().toUtc().toIso8601String(),
|
||||
'content': content,
|
||||
'topLetter': mostFrequentLetter,
|
||||
'topLetterFrequency': mostFrequentLetterCount,
|
||||
@@ -433,6 +435,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,
|
||||
};
|
||||
|
Reference in New Issue
Block a user