simplified code across the app and consolidated duplicated helpers

This commit is contained in:
2026-09-27 17:29:54 +02:00
parent 3e856d0b1c
commit ee1240f71a
155 changed files with 1772 additions and 2546 deletions
@@ -11,6 +11,7 @@ import '../../../../state/app/infrastructure/loadable_state/view/loadable_state_
import '../../../../state/app/infrastructure/loadable_state/view/loadable_state_primary_loading.dart';
import '../../../../state/app/infrastructure/utility_widgets/bloc_module.dart';
import '../../../../widget/placeholder_view.dart';
import '../data/webdav_path.dart';
import '../widgets/file_element.dart';
import 'files_search_controller.dart';
@@ -80,8 +81,8 @@ class FilesSearchResults extends StatelessWidget {
visible: showErrorScreen,
message: errorMessage,
),
if (showEmpty) _emptyState(context),
if (hasContent) _resultList(context, combined),
if (showEmpty) _emptyState(),
if (hasContent) _resultList(combined),
],
),
),
@@ -89,7 +90,7 @@ class FilesSearchResults extends StatelessWidget {
);
}
Widget _emptyState(BuildContext context) => PlaceholderView(
Widget _emptyState() => PlaceholderView(
icon: Icons.search_off_outlined,
text: 'Keine Treffer gefunden.',
button: controller.isScoped
@@ -101,7 +102,7 @@ class FilesSearchResults extends StatelessWidget {
: null,
);
Widget _resultList(BuildContext context, List<CacheableFile> combined) {
Widget _resultList(List<CacheableFile> combined) {
final groups = _groupByParent(combined);
final orderedKeys = groups.keys.toList()..sort();
// Flat (folder header | file) rows built lazily: results can run into
@@ -117,7 +118,7 @@ class FilesSearchResults extends StatelessWidget {
itemCount: rows.length,
itemBuilder: (context, index) {
final (folder, file) = rows[index];
final segments = _segmentsOf(folder);
final segments = webdavSegmentsOf(folder);
if (file == null) {
return _FolderHeader(
key: ValueKey('folder:$folder'),
@@ -139,29 +140,14 @@ class FilesSearchResults extends StatelessWidget {
);
}
static final RegExp _edgeSlashes = RegExp(r'^/+|/+$');
Map<String, List<CacheableFile>> _groupByParent(List<CacheableFile> files) {
final map = <String, List<CacheableFile>>{};
for (final file in files) {
map.putIfAbsent(_parentOf(file), () => []).add(file);
final parent = '/${webdavParentSegmentsOf(file.path).join('/')}';
map.putIfAbsent(parent, () => []).add(file);
}
return map;
}
String _parentOf(CacheableFile file) {
final stripped = file.path.replaceAll(_edgeSlashes, '');
final segments = stripped.split('/');
if (segments.length <= 1) return '/';
segments.removeLast();
return '/${segments.join('/')}';
}
List<String> _segmentsOf(String folder) {
final stripped = folder.replaceAll(_edgeSlashes, '');
if (stripped.isEmpty) return const [];
return stripped.split('/');
}
}
class _FolderHeader extends StatelessWidget {