Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Refactor title handling for note

AmanRajSinghMourya439a59c44a7e
diff --git a/mobile/apps/locker/lib/services/info_file_service.dart b/mobile/apps/locker/lib/services/info_file_service.dart
index 89b86dd489..e0b3a30828 100644
--- a/mobile/apps/locker/lib/services/info_file_service.dart
+++ b/mobile/apps/locker/lib/services/info_file_service.dart
@@ -72,9 +72,10 @@ class InfoFileService {
infoKey: infoData,
};
- // Update title if it's different
+ // Update title if it's different from current display name
+ // Use displayName (which considers editedName) instead of title (original name)
final updatedTitle = getInfoFileTitle(updatedInfoItem);
- if (existingFile.title != updatedTitle) {
+ if (existingFile.displayName != updatedTitle) {
metadataUpdates[editNameKey] = updatedTitle;
metadataUpdates[editTimeKey] = DateTime.now().millisecondsSinceEpoch;
}
diff --git a/mobile/apps/locker/lib/ui/pages/base_info_page.dart b/mobile/apps/locker/lib/ui/pages/base_info_page.dart
index a18ce62cf3..4ae29d259c 100644
--- a/mobile/apps/locker/lib/ui/pages/base_info_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/base_info_page.dart
@@ -335,19 +335,13 @@ abstract class BaseInfoPageState<T extends InfoData, W extends BaseInfoPage<T>>
await _updateCollectionMembership();
// Update the local data to reflect the changes in the UI
- // The metadata updater service already updated the file object locally
- // Now extract the updated info data and refresh the UI
- final updatedInfo =
- InfoFileService.instance.extractInfoFromFile(widget.existingFile!);
- if (updatedInfo != null) {
- // Update the current data state to show the new values in view mode
- setState(() {
- _currentData = updatedInfo.data as T?;
- });
+ // Use the infoItem data directly since it contains the updated values
+ setState(() {
+ _currentData = infoItem.data as T?;
+ });
- // Refresh UI with updated data
- refreshUIWithCurrentData();
- }
+ // Refresh UI with updated data
+ refreshUIWithCurrentData();
// The info file service already performs a sync, so we don't need to sync again
}
diff --git a/mobile/apps/locker/lib/ui/pages/personal_note_page.dart b/mobile/apps/locker/lib/ui/pages/personal_note_page.dart
index 5690fc5c70..4536d77efc 100644
--- a/mobile/apps/locker/lib/ui/pages/personal_note_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/personal_note_page.dart
@@ -4,7 +4,6 @@ import 'package:ente_ui/theme/ente_theme.dart';
import 'package:ente_ui/utils/toast_util.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
-import 'package:intl/intl.dart';
import 'package:locker/l10n/l10n.dart';
import 'package:locker/models/info/info_item.dart';
import 'package:locker/ui/components/collection_selection_widget.dart';
@@ -25,7 +24,6 @@ class PersonalNotePage extends BaseInfoPage<PersonalNoteData> {
class _PersonalNotePageState
extends BaseInfoPageState<PersonalNoteData, PersonalNotePage> {
- static const String _defaultTitle = 'Note title';
static const double _editorMinWidth = 320.0;
static const double _editorMaxWidth = 720.0;
static const double _editorWidthFactor = 0.92;
@@ -54,7 +52,6 @@ class _PersonalNotePageState
@override
void loadExistingData() {
_syncControllers(
- selectAllTitle: true,
triggerSetState: false,
updateInitial: true,
);
@@ -64,7 +61,6 @@ class _PersonalNotePageState
void refreshUIWithCurrentData() {
super.refreshUIWithCurrentData();
_syncControllers(
- selectAllTitle: false,
triggerSetState: true,
updateInitial: true,
);
@@ -111,7 +107,9 @@ class _PersonalNotePageState
@override
bool validateForm() {
- return _contentController.text.trim().isNotEmpty;
+ final title = _nameController.text.trim();
+ final content = _contentController.text.trim();
+ return title.isNotEmpty && content.isNotEmpty;
}
@override
@@ -315,6 +313,8 @@ class _PersonalNotePageState
}
_titleFocusNode.canRequestFocus = isEditing;
+ final colorScheme = getEnteColorScheme(context);
+
return TextField(
controller: _nameController,
focusNode: _titleFocusNode,
@@ -322,10 +322,12 @@ class _PersonalNotePageState
showCursor: isEditing,
enableInteractiveSelection: true,
style: textTheme.h3Bold,
- decoration: const InputDecoration(
+ decoration: InputDecoration(
border: InputBorder.none,
isDense: true,
contentPadding: EdgeInsets.zero,
+ hintText: context.l10n.noteNameHint,
+ hintStyle: textTheme.h3Bold.copyWith(color: colorScheme.textFaint),
),
textCapitalization: TextCapitalization.sentences,
maxLines: 1,
@@ -333,21 +335,13 @@ class _PersonalNotePageState
}
void _syncControllers({
- bool selectAllTitle = false,
bool triggerSetState = true,
bool updateInitial = false,
}) {
_isControllerSyncInProgress = true;
try {
final data = currentData;
- final trimmedTitle = data?.title.trim() ?? '';
- final effectiveTitle =
- trimmedTitle.isEmpty ? _defaultTitle : trimmedTitle;
- final shouldSelectAll = selectAllTitle && trimmedTitle.isEmpty;
- _updateTitleController(
- effectiveTitle,
- selectAll: shouldSelectAll,
- );
+ _nameController.text = data?.title ?? '';
_contentController.text = data?.content ?? '';
if (updateInitial) {
_initialContent = _contentController.text;
@@ -393,14 +387,6 @@ class _PersonalNotePageState
if (_isControllerSyncInProgress) {
return;
}
-
- final titleText = _nameController.text.trim();
- final contentText = _contentController.text.trim();
- if (titleText == _defaultTitle && contentText.isNotEmpty) {
- final generatedTitle = _formatCurrentTimestamp();
- _updateTitleController(generatedTitle);
- }
-
_notifyFormChanged();
}
@@ -414,38 +400,11 @@ class _PersonalNotePageState
return _contentController.text.trim() != _initialContent.trim();
}
- void _updateTitleController(String value, {bool selectAll = false}) {
- _nameController.value = TextEditingValue(
- text: value,
- selection: selectAll
- ? TextSelection(baseOffset: 0, extentOffset: value.length)
- : TextSelection.collapsed(offset: value.length),
- );
- }
-
- String _formatCurrentTimestamp() {
- final now = DateTime.now();
- final monthAbbreviation = DateFormat('MMM').format(now);
- final day = DateFormat('d').format(now);
- final year = DateFormat('yyyy').format(now);
- final time = DateFormat('h:mma').format(now).toLowerCase();
- return '$monthAbbreviation $day, $year - $time';
- }
-
void _onTitleFocusChanged() {
if (_isControllerSyncInProgress) {
return;
}
-
- if (_titleFocusNode.hasFocus) {
- if (_nameController.text.trim() == _defaultTitle) {
- _updateTitleController('');
- }
- } else {
- if (_nameController.text.trim().isEmpty) {
- _updateTitleController(_defaultTitle);
- }
- }
+ _notifyFormChanged();
}
void _onContentFocusChanged() {
@@ -478,7 +437,6 @@ class _PersonalNotePageState
}
_syncControllers(
- selectAllTitle: false,
triggerSetState: true,
updateInitial: false,
);