Skip to content

Commit

Permalink
Add option to reoder area
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Feb 14, 2024
1 parent 5f031f4 commit 4995406
Show file tree
Hide file tree
Showing 6 changed files with 828 additions and 47 deletions.
5 changes: 5 additions & 0 deletions api/lib/src/protocol/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ class DocumentEvent extends ReplayEvent with _$DocumentEvent {
Area area,
) = AreaChanged;

const factory DocumentEvent.areaReordered(
String name,
int newIndex,
) = AreaReordered;

const factory DocumentEvent.currentAreaChanged(
String name,
) = CurrentAreaChanged;
Expand Down
829 changes: 783 additions & 46 deletions api/lib/src/protocol/event.freezed.dart

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions api/lib/src/protocol/event.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions app/lib/bloc/document_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,19 @@ class DocumentBloc extends ReplayBloc<DocumentEvent, DocumentState> {
}
}
});
on<AreaReordered>((event, emit) {
final current = state;
if (current is! DocumentLoadSuccess) return;
if (!(current.embedding?.editable ?? true)) return;
final areas = List<Area>.from(current.page.areas);
final area =
areas.firstWhereOrNull((element) => element.name == event.name);
if (area == null) return;
areas.remove(area);
areas.insert(event.newIndex, area);
final currentDocument = current.page.copyWith(areas: areas);
_saveState(emit, current.copyWith(page: currentDocument));
});
on<ExportPresetCreated>((event, emit) {
final current = state;
if (current is! DocumentLoadSuccess) return;
Expand Down
7 changes: 7 additions & 0 deletions app/lib/handlers/area.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ class AreaHandler extends Handler<AreaTool> {
context.getCameraTransform().localToGlobal(localPosition);
final areas = state.page.getAreas(globalPosition, distance);
var area = areas.firstOrNull ?? state.currentArea;
if (_selectionManager.isValid) {
if (_selectionManager.selection.contains(globalPosition)) {
area = _currentArea;
}
_selectionManager.deselect();
_currentArea = null;
}
if (area == null) return;
if (areas.length > 1) {
area = await showDialog<Area>(
Expand Down
7 changes: 6 additions & 1 deletion app/lib/views/navigator/areas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,17 @@ class AreasView extends StatelessWidget {
.contains(
_searchController.text.toLowerCase()))
.toList();
return ListView.builder(
return ReorderableListView.builder(
itemCount: areas.length,
onReorder: (oldIndex, newIndex) => context
.read<DocumentBloc>()
.add(AreaReordered(
areas[oldIndex].name, newIndex)),
itemBuilder: (BuildContext context, int index) {
final area = areas[index];
return EditableListTile(
initialValue: area.name,
key: ValueKey(area.name),
onTap: () {
final screen = context
.read<CurrentIndexCubit>()
Expand Down

0 comments on commit 4995406

Please sign in to comment.