update position table, set selected table

This commit is contained in:
efrilm
2025-10-26 18:06:09 +07:00
parent 655902a659
commit 634b331716
15 changed files with 1195 additions and 61 deletions
@@ -1,3 +1,5 @@
import 'dart:ui';
import 'package:bloc/bloc.dart';
import 'package:dartz/dartz.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@@ -21,6 +23,15 @@ class TableLoaderBloc extends Bloc<TableLoaderEvent, TableLoaderState> {
Emitter<TableLoaderState> emit,
) {
return event.map(
setSelectedTable: (e) async {
if (e.table == null) {
emit(state.copyWith(selectedTable: null));
} else {
if (e.table?.status.isAvailable ?? false) {
emit(state.copyWith(selectedTable: e.table));
}
}
},
fetched: (e) async {
var newState = state;
@@ -32,6 +43,19 @@ class TableLoaderBloc extends Bloc<TableLoaderEvent, TableLoaderState> {
newState = await _mapFetchedToState(newState, isRefresh: e.isRefresh);
emit(newState);
},
updatedPostion: (e) async {
final updatedTables = state.tables.map((table) {
if (table.id == e.id) {
return table.copyWith(
positionX: e.position.dx,
positionY: e.position.dy,
);
}
return table;
}).toList();
emit(state.copyWith(tables: updatedTables));
},
);
}