Skip to content

Commit

Permalink
Fix problems using the new select system
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed May 9, 2024
1 parent 2a6ce00 commit 7e1f5ad
Show file tree
Hide file tree
Showing 17 changed files with 1,448 additions and 1,462 deletions.
24 changes: 17 additions & 7 deletions api/lib/models/event/item/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,30 @@ class CalendarItemDatabaseService extends CalendarItemService
final result = await db?.query(
"calendarItems LEFT JOIN events ON events.id = calendarItems.eventId",
columns: [
"events.*",
"events.id AS event_id",
"events.parentId AS event_parentId",
"events.groupId AS event_groupId",
"events.placeId AS event_placeId",
"events.blocked AS event_blocked",
"events.name AS event_name",
"events.description AS event_description",
"events.location AS event_location",
"events.extra AS event_extra",
"calendarItems.*",
],
where: where,
whereArgs: whereArgs,
);
const itemsPrefix = "calendarItems.";
const eventPrefix = "event_";
return result?.map((e) {
return ConnectedModel<CalendarItem, Event?>(
CalendarItem.fromDatabase(Map.fromEntries(e.entries
.where((element) => element.key.startsWith(itemsPrefix))
.map((e) =>
MapEntry(e.key.substring(itemsPrefix.length), e.value)))),
e['id'] == null ? null : Event.fromDatabase(e),
CalendarItem.fromDatabase(e),
e['${eventPrefix}id'] == null
? null
: Event.fromDatabase(Map.fromEntries(e.entries
.where((element) => element.key.startsWith(eventPrefix))
.map((e) => MapEntry(
e.key.substring(eventPrefix.length), e.value)))),
);
}).toList() ??
[];
Expand Down
8 changes: 4 additions & 4 deletions api/lib/models/note/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ abstract class NoteDatabaseConnector<T> extends NoteConnector<T>
}

class NoteDatabaseService extends NoteService with TableService {
Future<void> _createNotebookDatabase() async {
await db?.execute("""
Future<void> _createNotebookDatabase(Database db) async {
await db.execute("""
CREATE TABLE IF NOT EXISTS notebooks (
id BLOB(16) PRIMARY KEY,
name VARCHAR(100) NOT NULL DEFAULT '',
Expand All @@ -142,14 +142,14 @@ class NoteDatabaseService extends NoteService with TableService {
parentId BLOB(16)
)
""");
await _createNotebookDatabase();
await _createNotebookDatabase(db);
}

@override
Future<void> migrate(Database db, int version) async {
if (version < 3) {
await db.execute("ALTER TABLE notes ADD notebookId BLOB(16)");
await _createNotebookDatabase();
await _createNotebookDatabase(db);
}
}

Expand Down
16 changes: 8 additions & 8 deletions api/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ packages:
dependency: transitive
description:
name: coverage
sha256: "8acabb8306b57a409bf4c83522065672ee13179297a6bb0cb9ead73948df7c76"
sha256: "3945034e86ea203af7a056d98e98e42a5518fff200d6e8e6647e1886b07e936e"
url: "https://pub.dev"
source: hosted
version: "1.7.2"
version: "1.8.0"
crypto:
dependency: transitive
description:
Expand Down Expand Up @@ -334,10 +334,10 @@ packages:
dependency: "direct main"
description:
name: meta
sha256: "25dfcaf170a0190f47ca6355bdd4552cb8924b430512ff0cafb8db9bd41fe33b"
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
url: "https://pub.dev"
source: hosted
version: "1.14.0"
version: "1.15.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -534,10 +534,10 @@ packages:
dependency: "direct dev"
description:
name: test
sha256: d72b538180efcf8413cd2e4e6fcc7ae99c7712e0909eb9223f9da6e6d0ef715f
sha256: d11b55850c68c1f6c0cf00eabded4e66c4043feaf6c0d7ce4a36785137df6331
url: "https://pub.dev"
source: hosted
version: "1.25.4"
version: "1.25.5"
test_api:
dependency: transitive
description:
Expand Down Expand Up @@ -582,10 +582,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
sha256: "7475cb4dd713d57b6f7464c0e13f06da0d535d8b2067e188962a59bac2cf280b"
url: "https://pub.dev"
source: hosted
version: "14.2.1"
version: "14.2.2"
watcher:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion app/lib/pages/events/select.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class EventSelectTile extends StatelessWidget {
onChanged: onChanged,
onModelFetch: (source, service, id) async => service.event?.getEvent(id),
title: AppLocalizations.of(context).event,
leadingBuilder: (context, model) => PhosphorIcon(model.model == null
leadingBuilder: (context, model) => PhosphorIcon(model?.model == null
? PhosphorIconsLight.calendar
: PhosphorIconsFill.calendar),
dialogBuilder: (context, sourcedModel) => EventDialog(
Expand Down
2 changes: 1 addition & 1 deletion app/lib/pages/groups/select.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class GroupSelectTile extends StatelessWidget {
onChanged: onChanged,
onModelFetch: (source, service, id) async => service.group?.getGroup(id),
title: AppLocalizations.of(context).group,
leadingBuilder: (context, model) => PhosphorIcon(model.model == null
leadingBuilder: (context, model) => PhosphorIcon(model?.model == null
? PhosphorIconsLight.users
: PhosphorIconsFill.users),
dialogBuilder: (context, sourcedModel) => GroupDialog(
Expand Down
4 changes: 1 addition & 3 deletions app/lib/pages/notes/navigator/children.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ class _NoteChildrenViewState extends State<_NoteChildrenView> {
void initState() {
super.initState();

_controller = SourcedPagingController(
context.read<FlowCubit>(),
);
_controller = SourcedPagingController(context.read<FlowCubit>());
_controller.addFetchListener((source, service, offset, limit) async {
final notebook = widget.notebook;
if (notebook != null && notebook.source != source) return [];
Expand Down
26 changes: 6 additions & 20 deletions app/lib/pages/notes/navigator/drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,17 @@ class NotesNavigatorDrawer extends StatelessWidget {
length: 2,
child: Column(
children: [
_NotebooksView(
model: sourcedNotebook,
),
_NoteLabelsView(
onChanged: onLabelChanged,
selected: selectedLabel,
),
TabBar(tabs: [
HorizontalTab(
label: Text(AppLocalizations.of(context).notes),
icon: const PhosphorIcon(PhosphorIconsLight.article),
),
HorizontalTab(
label: Text(AppLocalizations.of(context).notebooks),
icon: const PhosphorIcon(PhosphorIconsLight.fileArchive),
),
]),
Expanded(
child: TabBarView(
children: [
_NoteChildrenView(
parent: note,
notebook: sourcedNotebook,
),
_NotebooksView(
model: sourcedNotebook,
),
],
child: _NoteChildrenView(
parent: note,
notebook: sourcedNotebook,
),
),
],
Expand Down
6 changes: 4 additions & 2 deletions app/lib/pages/notes/navigator/labels.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ class _NoteLabelsViewState extends State<_NoteLabelsView> {
child: Text(AppLocalizations.of(context).edit),
onPressed: () => showDialog(
context: context,
builder: (context) =>
LabelDialog(label: item.model))
builder: (context) => LabelDialog(
source: item.source,
label: item.model,
))
.then((value) => _pagingController.refresh())),
MenuItemButton(
leadingIcon:
Expand Down
2 changes: 1 addition & 1 deletion app/lib/pages/notes/navigator/notebooks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class _NotebooksView extends StatelessWidget {
service.note?.getNotebook(id),
title: AppLocalizations.of(context).notebooks,
leadingBuilder: (context, model) => PhosphorIcon(
model.model == null ? PhosphorIconsLight.book : PhosphorIconsFill.book,
model?.model == null ? PhosphorIconsLight.book : PhosphorIconsFill.book,
),
dialogBuilder: (context, model) => NotebookDialog(
source: model?.source,
Expand Down
5 changes: 3 additions & 2 deletions app/lib/pages/notes/select.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class LabelSelectTile extends StatelessWidget {
onChanged: onChanged,
onModelFetch: (source, service, id) async => service.label?.getLabel(id),
title: AppLocalizations.of(context).label,
leadingBuilder: (context, model) => PhosphorIcon(
model.model == null ? PhosphorIconsLight.tag : PhosphorIconsFill.tag),
leadingBuilder: (context, model) => PhosphorIcon(model?.model == null
? PhosphorIconsLight.tag
: PhosphorIconsFill.tag),
dialogBuilder: (context, sourcedModel) => LabelDialog(
source: sourcedModel?.source,
label: sourcedModel?.model,
Expand Down
2 changes: 1 addition & 1 deletion app/lib/pages/places/select.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PlaceSelectTile extends StatelessWidget {
onChanged: onChanged,
onModelFetch: (source, service, id) async => service.place?.getPlace(id),
title: AppLocalizations.of(context).place,
leadingBuilder: (context, model) => PhosphorIcon(model.model == null
leadingBuilder: (context, model) => PhosphorIcon(model?.model == null
? PhosphorIconsLight.mapPin
: PhosphorIconsFill.mapPin),
dialogBuilder: (context, sourcedModel) => PlaceDialog(
Expand Down
6 changes: 4 additions & 2 deletions app/lib/widgets/select.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import '../../widgets/builder_delegate.dart';
typedef ModelFetchCallback<T> = Future<T?> Function(
String source, SourceService service, Multihash id);
typedef ModelWidgetBuilder<T> = Widget? Function(
BuildContext context, SourcedModel<T?> model);
BuildContext context, SourcedModel<T?>? model);
typedef ModelSelectBuilder<T> = Widget Function(
BuildContext context, SourcedModel<T?>? model);

Expand Down Expand Up @@ -73,7 +73,9 @@ class _SelectTileState<T extends NamedModel> extends State<SelectTile<T>> {
_value!.model)),
builder: (context, snapshot) {
final model = snapshot.data;
final sourcedModel = SourcedModel(_value!.source, model);
final sourcedModel = _value?.source == null
? null
: SourcedModel(_value!.source, model);
return ListTile(
title: Text(widget.title),
subtitle: Text(model?.name ?? AppLocalizations.of(context).notSet),
Expand Down
52 changes: 26 additions & 26 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,10 @@ packages:
dependency: "direct main"
description:
name: file_picker
sha256: "45c70b43df893027e441a6fa0aacc8f484fb9f9c60c746dc8f1dc4f774cf55cd"
sha256: "29c90806ac5f5fb896547720b73b17ee9aed9bba540dc5d91fe29f8c5745b10a"
url: "https://pub.dev"
source: hosted
version: "8.0.2"
version: "8.0.3"
fixnum:
dependency: transitive
description:
Expand Down Expand Up @@ -383,51 +383,51 @@ packages:
dependency: "direct main"
description:
name: flutter_secure_storage
sha256: ffdbb60130e4665d2af814a0267c481bcf522c41ae2e43caf69fa0146876d685
sha256: c0f402067fb0498934faa6bddd670de0a3db45222e2ca9a068c6177c9a2360a4
url: "https://pub.dev"
source: hosted
version: "9.0.0"
version: "9.1.1"
flutter_secure_storage_linux:
dependency: transitive
description:
name: flutter_secure_storage_linux
sha256: "3d5032e314774ee0e1a7d0a9f5e2793486f0dff2dd9ef5a23f4e3fb2a0ae6a9e"
sha256: "4d91bfc23047422cbcd73ac684bc169859ee766482517c22172c86596bf1464b"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
version: "1.2.1"
flutter_secure_storage_macos:
dependency: transitive
description:
name: flutter_secure_storage_macos
sha256: bd33935b4b628abd0b86c8ca20655c5b36275c3a3f5194769a7b3f37c905369c
sha256: "8cfa53010a294ff095d7be8fa5bb15f2252c50018d69c5104851303f3ff92510"
url: "https://pub.dev"
source: hosted
version: "3.0.1"
version: "3.1.0"
flutter_secure_storage_platform_interface:
dependency: transitive
description:
name: flutter_secure_storage_platform_interface
sha256: "0d4d3a5dd4db28c96ae414d7ba3b8422fd735a8255642774803b2532c9a61d7e"
sha256: "301f67ee9b87f04aef227f57f13f126fa7b13543c8e7a93f25c5d2d534c28a4a"
url: "https://pub.dev"
source: hosted
version: "1.0.2"
version: "1.1.1"
flutter_secure_storage_web:
dependency: "direct overridden"
description:
path: flutter_secure_storage_web
ref: "6ac827e457393b5c654c1abda40d31e2cb93f62c"
resolved-ref: "6ac827e457393b5c654c1abda40d31e2cb93f62c"
url: "https://github.com/ThexXTURBOXx/flutter_secure_storage.git"
ref: ce09c8a5fd2b3a48949e386c7cc2849451961b46
resolved-ref: ce09c8a5fd2b3a48949e386c7cc2849451961b46
url: "https://github.com/CodeDoctorDE/flutter_secure_storage.git"
source: git
version: "1.2.0"
version: "1.1.2"
flutter_secure_storage_windows:
dependency: transitive
description:
name: flutter_secure_storage_windows
sha256: "5809c66f9dd3b4b93b0a6e2e8561539405322ee767ac2f64d084e2ab5429d108"
sha256: b20b07cb5ed4ed74fc567b78a72936203f587eba460af1df11281c9326cd3709
url: "https://pub.dev"
source: hosted
version: "3.0.0"
version: "3.1.2"
flutter_staggered_grid_view:
dependency: transitive
description:
Expand Down Expand Up @@ -482,10 +482,10 @@ packages:
dependency: "direct main"
description:
name: go_router
sha256: "28ef8a8320ab3bf5752424e6bca6961ce25108afc344f3127b5155caf7a792c8"
sha256: "9e0f7d1a3e7dc5010903e330fbc5497872c4c3cf6626381d69083cc1d5113c1e"
url: "https://pub.dev"
source: hosted
version: "14.0.0"
version: "14.0.2"
graphs:
dependency: transitive
description:
Expand Down Expand Up @@ -731,10 +731,10 @@ packages:
dependency: transitive
description:
name: path_provider_foundation
sha256: "5a7999be66e000916500be4f15a3633ebceb8302719b47b9cc49ce924125350f"
sha256: f234384a3fdd67f989b4d54a5d73ca2a6c422fa55ae694381ae0f4375cd1ea16
url: "https://pub.dev"
source: hosted
version: "2.3.2"
version: "2.4.0"
path_provider_linux:
dependency: transitive
description:
Expand Down Expand Up @@ -876,10 +876,10 @@ packages:
dependency: transitive
description:
name: shared_preferences_foundation
sha256: "7708d83064f38060c7b39db12aefe449cb8cdc031d6062280087bc4cdb988f5c"
sha256: "0a8a893bf4fd1152f93fec03a415d11c27c74454d96e2318a7ac38dd18683ab7"
url: "https://pub.dev"
source: hosted
version: "2.3.5"
version: "2.4.0"
shared_preferences_linux:
dependency: transitive
description:
Expand Down Expand Up @@ -977,10 +977,10 @@ packages:
dependency: "direct main"
description:
name: sqflite
sha256: "5ce2e1a15e822c3b4bfb5400455775e421da7098eed8adc8f26298ada7c9308c"
sha256: a43e5a27235518c03ca238e7b4732cf35eabe863a369ceba6cbefa537a66f16d
url: "https://pub.dev"
source: hosted
version: "2.3.3"
version: "2.3.3+1"
sqflite_common:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1209,10 +1209,10 @@ packages:
dependency: transitive
description:
name: win32
sha256: "0a989dc7ca2bb51eac91e8fd00851297cfffd641aa7538b165c62637ca0eaa4a"
sha256: "0eaf06e3446824099858367950a813472af675116bf63f008a4c2a75ae13e9cb"
url: "https://pub.dev"
source: hosted
version: "5.4.0"
version: "5.5.0"
window_manager:
dependency: "direct main"
description:
Expand Down
Loading

0 comments on commit 7e1f5ad

Please sign in to comment.