some issues fixed
This commit is contained in:
@@ -42,26 +42,40 @@ class PreferencesController extends ChangeNotifier {
|
||||
);
|
||||
|
||||
List<OverviewFavourite> get overviewFavourites =>
|
||||
List.unmodifiable([
|
||||
for (final fav in _overviewFavourites)
|
||||
if (!fav.deleted) fav,
|
||||
]);
|
||||
|
||||
/// Full list including soft-deleted rows (for PocketBase push).
|
||||
List<OverviewFavourite> get overviewFavouritesForSync =>
|
||||
List.unmodifiable(_overviewFavourites);
|
||||
|
||||
List<OverviewFavourite> get displayedOverviewFavourites => [
|
||||
for (final fav in _overviewFavourites)
|
||||
if (fav.display) fav,
|
||||
if (!fav.deleted && fav.display) fav,
|
||||
];
|
||||
|
||||
bool get hasDisplayedOverviewFavourites =>
|
||||
_overviewFavourites.any((f) => f.display);
|
||||
_overviewFavourites.any((f) => !f.deleted && f.display);
|
||||
|
||||
List<HomeFilterWidget> get homeFilterWidgets =>
|
||||
List.unmodifiable([
|
||||
for (final w in _homeFilterWidgets)
|
||||
if (!w.deleted) w,
|
||||
]);
|
||||
|
||||
/// Full list including soft-deleted rows (for PocketBase push).
|
||||
List<HomeFilterWidget> get homeFilterWidgetsForSync =>
|
||||
List.unmodifiable(_homeFilterWidgets);
|
||||
|
||||
List<HomeFilterWidget> get displayedHomeFilterWidgets => [
|
||||
for (final w in _homeFilterWidgets)
|
||||
if (w.display) w,
|
||||
if (!w.deleted && w.display) w,
|
||||
];
|
||||
|
||||
bool get hasDisplayedHomeFilterWidgets =>
|
||||
_homeFilterWidgets.any((w) => w.display);
|
||||
_homeFilterWidgets.any((w) => !w.deleted && w.display);
|
||||
|
||||
HomeBuiltInSections get homeBuiltInSections => _homeBuiltInSections;
|
||||
|
||||
@@ -118,7 +132,10 @@ class PreferencesController extends ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<void> addOverviewFavourite(OverviewFavourite favourite) async {
|
||||
_overviewFavourites = [..._overviewFavourites, favourite];
|
||||
final stamped = favourite.updatedAt == 0
|
||||
? favourite.copyWith(touchUpdatedAt: true)
|
||||
: favourite;
|
||||
_overviewFavourites = [..._overviewFavourites, stamped];
|
||||
notifyListeners();
|
||||
await _persistFavourites();
|
||||
}
|
||||
@@ -127,18 +144,19 @@ class PreferencesController extends ChangeNotifier {
|
||||
final index = _overviewFavourites.indexWhere((f) => f.id == favourite.id);
|
||||
if (index < 0) return;
|
||||
final next = [..._overviewFavourites];
|
||||
next[index] = favourite;
|
||||
next[index] = favourite.copyWith(touchUpdatedAt: true);
|
||||
_overviewFavourites = next;
|
||||
notifyListeners();
|
||||
await _persistFavourites();
|
||||
}
|
||||
|
||||
Future<void> removeOverviewFavourite(String id) async {
|
||||
final next = [
|
||||
for (final fav in _overviewFavourites)
|
||||
if (fav.id != id) fav,
|
||||
];
|
||||
if (next.length == _overviewFavourites.length) return;
|
||||
final index = _overviewFavourites.indexWhere((f) => f.id == id);
|
||||
if (index < 0) return;
|
||||
final current = _overviewFavourites[index];
|
||||
if (current.deleted) return;
|
||||
final next = [..._overviewFavourites];
|
||||
next[index] = current.copyWith(deleted: true, touchUpdatedAt: true);
|
||||
_overviewFavourites = next;
|
||||
notifyListeners();
|
||||
await _persistFavourites();
|
||||
@@ -148,7 +166,7 @@ class PreferencesController extends ChangeNotifier {
|
||||
final index = _overviewFavourites.indexWhere((f) => f.id == id);
|
||||
if (index < 0) return;
|
||||
final current = _overviewFavourites[index];
|
||||
if (current.display == display) return;
|
||||
if (current.deleted || current.display == display) return;
|
||||
await updateOverviewFavourite(current.copyWith(display: display));
|
||||
}
|
||||
|
||||
@@ -164,16 +182,20 @@ class PreferencesController extends ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<void> addHomeFilterWidget(HomeFilterWidget widget) async {
|
||||
final order = _homeFilterWidgets.isEmpty
|
||||
final order = _homeFilterWidgets.where((w) => !w.deleted).isEmpty
|
||||
? 0
|
||||
: _homeFilterWidgets
|
||||
.where((w) => !w.deleted)
|
||||
.map((w) => w.sortOrder)
|
||||
.reduce((a, b) => a > b ? a : b) +
|
||||
1;
|
||||
_homeFilterWidgets = [
|
||||
..._homeFilterWidgets,
|
||||
widget.copyWith(sortOrder: widget.sortOrder == 0 ? order : widget.sortOrder),
|
||||
];
|
||||
final stamped = (widget.updatedAt == 0
|
||||
? widget.copyWith(touchUpdatedAt: true)
|
||||
: widget)
|
||||
.copyWith(
|
||||
sortOrder: widget.sortOrder == 0 ? order : widget.sortOrder,
|
||||
);
|
||||
_homeFilterWidgets = [..._homeFilterWidgets, stamped];
|
||||
notifyListeners();
|
||||
await _persistHomeWidgets();
|
||||
}
|
||||
@@ -182,7 +204,7 @@ class PreferencesController extends ChangeNotifier {
|
||||
final index = _homeFilterWidgets.indexWhere((w) => w.id == widget.id);
|
||||
if (index < 0) return;
|
||||
final next = [..._homeFilterWidgets];
|
||||
next[index] = widget;
|
||||
next[index] = widget.copyWith(touchUpdatedAt: true);
|
||||
next.sort((a, b) => a.sortOrder.compareTo(b.sortOrder));
|
||||
_homeFilterWidgets = next;
|
||||
notifyListeners();
|
||||
@@ -190,11 +212,12 @@ class PreferencesController extends ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<void> removeHomeFilterWidget(String id) async {
|
||||
final next = [
|
||||
for (final w in _homeFilterWidgets)
|
||||
if (w.id != id) w,
|
||||
];
|
||||
if (next.length == _homeFilterWidgets.length) return;
|
||||
final index = _homeFilterWidgets.indexWhere((w) => w.id == id);
|
||||
if (index < 0) return;
|
||||
final current = _homeFilterWidgets[index];
|
||||
if (current.deleted) return;
|
||||
final next = [..._homeFilterWidgets];
|
||||
next[index] = current.copyWith(deleted: true, touchUpdatedAt: true);
|
||||
_homeFilterWidgets = next;
|
||||
notifyListeners();
|
||||
await _persistHomeWidgets();
|
||||
@@ -204,19 +227,32 @@ class PreferencesController extends ChangeNotifier {
|
||||
final index = _homeFilterWidgets.indexWhere((w) => w.id == id);
|
||||
if (index < 0) return;
|
||||
final current = _homeFilterWidgets[index];
|
||||
if (current.display == display) return;
|
||||
if (current.deleted || current.display == display) return;
|
||||
await updateHomeFilterWidget(current.copyWith(display: display));
|
||||
}
|
||||
|
||||
Future<void> reorderHomeFilterWidgets(int oldIndex, int newIndex) async {
|
||||
if (oldIndex == newIndex) return;
|
||||
final next = [..._homeFilterWidgets];
|
||||
final item = next.removeAt(oldIndex);
|
||||
final target = newIndex.clamp(0, next.length);
|
||||
next.insert(target, item);
|
||||
_homeFilterWidgets = [
|
||||
for (var i = 0; i < next.length; i++) next[i].copyWith(sortOrder: i),
|
||||
final visible = [
|
||||
for (final w in _homeFilterWidgets)
|
||||
if (!w.deleted) w,
|
||||
];
|
||||
if (oldIndex < 0 || oldIndex >= visible.length) return;
|
||||
final nextVisible = [...visible];
|
||||
final item = nextVisible.removeAt(oldIndex);
|
||||
final target = newIndex.clamp(0, nextVisible.length);
|
||||
nextVisible.insert(target, item);
|
||||
final orderById = <String, int>{
|
||||
for (var i = 0; i < nextVisible.length; i++) nextVisible[i].id: i,
|
||||
};
|
||||
final now = DateTime.now().millisecondsSinceEpoch;
|
||||
_homeFilterWidgets = [
|
||||
for (final w in _homeFilterWidgets)
|
||||
if (w.deleted)
|
||||
w
|
||||
else
|
||||
w.copyWith(sortOrder: orderById[w.id] ?? w.sortOrder, updatedAt: now),
|
||||
]..sort((a, b) => a.sortOrder.compareTo(b.sortOrder));
|
||||
notifyListeners();
|
||||
await _persistHomeWidgets();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user