Add functionality to edit sheets with save and restore
This commit is contained in:
66
lib/upload_queue.dart
Normal file
66
lib/upload_queue.dart
Normal file
@@ -0,0 +1,66 @@
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:sheetless/sheet.dart';
|
||||
|
||||
enum ChangeType {
|
||||
sheetNameChange,
|
||||
composerNameChange,
|
||||
addTagChange,
|
||||
removeTagChange,
|
||||
}
|
||||
|
||||
class Change {
|
||||
final ChangeType type;
|
||||
final String sheetUuid;
|
||||
final String value;
|
||||
|
||||
Change({required this.type, required this.sheetUuid, required this.value});
|
||||
|
||||
Map<String, dynamic> toMap() => {
|
||||
"type": type.index,
|
||||
"sheetUuid": sheetUuid,
|
||||
"value": value,
|
||||
};
|
||||
|
||||
factory Change.fromMap(Map<dynamic, dynamic> map) {
|
||||
return Change(
|
||||
type: ChangeType
|
||||
.values[map["type"]], // TODO: this will create problems if new enums are added
|
||||
sheetUuid: map["sheetUuid"],
|
||||
value: map["value"],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ChangeQueue {
|
||||
// Queue with oldest change first
|
||||
final Queue<Change> queue = Queue();
|
||||
|
||||
ChangeQueue() {}
|
||||
|
||||
void addChange(Change change) {
|
||||
queue.addLast(change);
|
||||
}
|
||||
|
||||
int length() {
|
||||
return queue.length;
|
||||
}
|
||||
|
||||
void applyToSheets(List<Sheet> sheets) {
|
||||
for (Change change in queue) {
|
||||
var sheet = sheets.where((sheet) => sheet.uuid == change.sheetUuid).first;
|
||||
switch (change.type) {
|
||||
case ChangeType.sheetNameChange:
|
||||
sheet.name = change.value;
|
||||
case ChangeType.composerNameChange:
|
||||
sheet.composerName = change.value;
|
||||
case ChangeType.addTagChange:
|
||||
// TODO: Handle this case.
|
||||
throw UnimplementedError();
|
||||
case ChangeType.removeTagChange:
|
||||
// TODO: Handle this case.
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user