Skip to content

Commit

Permalink
Start with notes drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Jan 14, 2024
1 parent 7c5c4c3 commit 240b893
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 115 deletions.
20 changes: 14 additions & 6 deletions api/lib/models/note/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,20 @@ class NoteDatabaseService extends NoteService with TableService {
}

@override
Future<Note?> getNote(Multihash id) async {
final result = await db?.query(
'notes',
where: 'id = ?',
whereArgs: [id.fullBytes],
);
Future<Note?> getNote(Multihash id, {bool fallback = false}) async {
final result = fallback
? await db?.rawQuery(
"""SELECT * FROM notes
WHERE slug = ? OR slug = (SELECT MIN(slug) FROM notes)
ORDER BY slug DESC
LIMIT 1;""",
[id.fullBytes],
)
: await db?.query(
'notes',
where: 'id = ?',
whereArgs: [id.fullBytes],
);
return result?.map(Note.fromDatabase).firstOrNull;
}
}
2 changes: 1 addition & 1 deletion api/lib/models/note/service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract class NoteService extends ModelService {

FutureOr<bool> deleteNote(Multihash id);

FutureOr<Note?> getNote(Multihash id);
FutureOr<Note?> getNote(Multihash id, {bool fallback = false});
}

abstract class NoteConnector<T> extends ModelService {
Expand Down
2 changes: 1 addition & 1 deletion api/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies:
dart_leap:
git:
url: https://github.com/LinwoodDev/dart_pkgs
ref: 47a223756447b027f6e0d2f7e537f4a1ca4bbce7
ref: 992f8062618ef1e78ee92efc7a709eb0d476e1d0
path: packages/dart_leap
dev_dependencies:
build_runner: ^2.4.7
Expand Down
16 changes: 8 additions & 8 deletions app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class FlowApp extends StatelessWidget {
(context, state) => const DashboardPage()),
routes: [
GoRoute(
path: '/calendar',
path: 'calendar',
pageBuilder: _fadeTransitionBuilder(
(context, state) => CalendarPage(
filter: state.extra is CalendarFilter
Expand All @@ -144,19 +144,19 @@ class FlowApp extends StatelessWidget {
),
),
GoRoute(
path: '/events',
path: 'events',
pageBuilder: _fadeTransitionBuilder(
(context, state) => const EventsPage(),
),
),
GoRoute(
path: '/groups',
path: 'groups',
pageBuilder: _fadeTransitionBuilder(
(context, state) => const GroupsPage(),
),
),
GoRoute(
path: '/notes',
path: 'notes',
pageBuilder: _fadeTransitionBuilder(
(context, state) => const NotesPage(),
),
Expand Down Expand Up @@ -189,13 +189,13 @@ class FlowApp extends StatelessWidget {
)
]),
GoRoute(
path: '/places',
path: 'places',
pageBuilder: _fadeTransitionBuilder(
(context, state) => const PlacesPage(),
),
),
GoRoute(
path: '/users',
path: 'users',
pageBuilder: _fadeTransitionBuilder(
(context, state) => UsersPage(
filter: state.extra is UserFilter
Expand All @@ -205,13 +205,13 @@ class FlowApp extends StatelessWidget {
),
),
GoRoute(
path: '/sources',
path: 'sources',
pageBuilder: _fadeTransitionBuilder(
(context, state) => const SourcesPage(),
),
),
GoRoute(
path: '/settings',
path: 'settings',
pageBuilder: _fadeTransitionBuilder(
(context, state) => const SettingsPage(),
),
Expand Down
4 changes: 2 additions & 2 deletions app/lib/pages/notes/label.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flow/widgets/color.dart';
import 'package:flow/widgets/markdown_field.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down Expand Up @@ -36,7 +35,7 @@ class LabelDialog extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
children: [
StatefulBuilder(
builder: (context, setState) => ColorPoint(
builder: (context, setState) => ColorButton(
onTap: () async {
final result = await showDialog<ColorPickerResponse>(
context: context,
Expand All @@ -46,6 +45,7 @@ class LabelDialog extends StatelessWidget {
currentLabel = currentLabel.copyWith(color: result.color));
},
color: Color(currentLabel.color).withAlpha(255),
size: 25,
),
),
const SizedBox(width: 16),
Expand Down
16 changes: 3 additions & 13 deletions app/lib/pages/notes/navigator/drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:flow/cubits/flow.dart';
import 'package:flow/helpers/sourced_paging_controller.dart';
import 'package:flow/pages/notes/label.dart';
import 'package:flow/widgets/builder_delegate.dart';
import 'package:flow/widgets/color.dart';
import 'package:flow_api/models/label/model.dart';
import 'package:flow_api/models/model.dart';
import 'package:flutter/material.dart';
Expand All @@ -29,18 +28,9 @@ class NotesNavigatorDrawer extends StatelessWidget {
Widget build(BuildContext context) {
return ListView(
children: [
ExpansionPanelList.radio(
children: [
ExpansionPanel(
headerBuilder: (context, isExpanded) => ListTile(
title: Text(AppLocalizations.of(context).labels),
),
body: _NoteLabelsView(
onChanged: onLabelChanged,
selected: selectedLabel,
),
),
],
_NoteLabelsView(
onChanged: onLabelChanged,
selected: selectedLabel,
),
],
);
Expand Down
98 changes: 46 additions & 52 deletions app/lib/pages/notes/navigator/labels.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,23 @@ class _NoteLabelsView extends StatefulWidget {
final Multihash? selected;
final LabelChangedCallback? onChanged;

const _NoteLabelsView({super.key, this.selected, this.onChanged});
const _NoteLabelsView({this.selected, this.onChanged});

@override
State<_NoteLabelsView> createState() => _NoteLabelsViewState();
}

class _NoteLabelsViewState extends State<_NoteLabelsView> {
late final SourcedPagingController<Label> _pagingController;
String _search = '';
late final FlowCubit _cubit;

@override
void initState() {
super.initState();
_cubit = context.read<FlowCubit>();
_pagingController = SourcedPagingController(_cubit);
_pagingController.addFetchListener((source, service, offset, limit) async =>
await service.label
?.getLabels(offset: offset, limit: limit, search: _search));
_pagingController.addFetchListener((source, service, offset, limit) =>
Future.value(service.label?.getLabels(offset: offset, limit: limit)));
}

@override
Expand All @@ -48,34 +46,45 @@ class _NoteLabelsViewState extends State<_NoteLabelsView> {
return Card(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(children: [
TextFormField(
decoration: InputDecoration(
labelText: AppLocalizations.of(context).search,
border: const OutlineInputBorder(),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
AppLocalizations.of(context).labels,
style: Theme.of(context).textTheme.titleMedium,
),
IconButton(
icon: const PhosphorIcon(PhosphorIconsLight.plus),
onPressed: () => showDialog(
context: context,
builder: (context) => const LabelDialog(),
).then((value) => _pagingController.refresh()),
),
],
),
onChanged: (value) {
_search = value;
_pagingController.refresh();
},
),
const SizedBox(height: 8),
Expanded(
child: PagedListView(
pagingController: _pagingController,
builderDelegate: buildMaterialPagedDelegate<SourcedModel<Label>>(
_pagingController,
(context, item, index) {
final selected = widget.selected == item.model.id;
return ListTile(
title: Text(item.model.name),
onTap: () {
widget.onChanged?.call(item, !selected);
},
selected: selected,
leading: ColorPoint(
color: Color(item.model.color).withAlpha(255)),
trailing: MenuAnchor(
SizedBox(
height: 50,
child: PagedListView(
scrollDirection: Axis.horizontal,
pagingController: _pagingController,
builderDelegate:
buildMaterialPagedDelegate<SourcedModel<Label>>(
_pagingController,
(context, item, index) {
final selected = widget.selected == item.model.id;
return MenuAnchor(
builder: (context, controller, child) => Tooltip(
message: item.model.name,
child: ColorButton(
onTap: () => widget.onChanged?.call(item, !selected),
selected: selected,
color: Color(item.model.color).withAlpha(255),
onLongPress: controller.toggle,
onSecondaryTap: controller.toggle,
),
),
menuChildren: [
MenuItemButton(
leadingIcon:
Expand Down Expand Up @@ -124,28 +133,13 @@ class _NoteLabelsViewState extends State<_NoteLabelsView> {
),
),
],
builder: (context, controller, child) => IconButton(
icon: const PhosphorIcon(
PhosphorIconsLight.dotsThreeVertical),
onPressed: () => controller.isOpen
? controller.close()
: controller.open(),
),
),
);
},
);
},
),
),
),
),
const Divider(),
OutlinedButton.icon(
icon: const PhosphorIcon(PhosphorIconsLight.plus),
label: Text(AppLocalizations.of(context).createLabel),
onPressed: () => showDialog(
context: context, builder: (context) => const LabelDialog())
.then((value) => _pagingController.refresh()),
)
]),
],
),
),
);
}
Expand Down
4 changes: 2 additions & 2 deletions app/lib/pages/notes/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class _NotesPageState extends State<NotesPage> {
return FlowNavigation(
title: AppLocalizations.of(context).notes,
endDrawer: NotesNavigatorDrawer(
selected: _filter.selectedLabel,
onChanged: (value, add) {
selectedLabel: _filter.selectedLabel,
onLabelChanged: (value, add) {
final source = value.source;
if (add) {
setState(() {
Expand Down
6 changes: 3 additions & 3 deletions app/lib/pages/notes/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:math';

import 'package:collection/collection.dart';
import 'package:flow/helpers/sourced_paging_controller.dart';
import 'package:flow/widgets/color.dart';
import 'package:flow/widgets/markdown_field.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down Expand Up @@ -261,8 +260,9 @@ class _NoteViewState extends State<NoteView> {
.map((e) => Padding(
padding: const EdgeInsets.all(8.0),
child: InputChip(
avatar: ColorPoint(
color: Color(e.color)),
avatar: ColorButton(
color: Color(e.color),
),
label: Text(e.name),
onDeleted: () async {
await _labelNoteService
Expand Down
22 changes: 0 additions & 22 deletions app/lib/widgets/color.dart

This file was deleted.

8 changes: 4 additions & 4 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ packages:
dependency: transitive
description:
path: "packages/dart_leap"
ref: "47a223756447b027f6e0d2f7e537f4a1ca4bbce7"
resolved-ref: "47a223756447b027f6e0d2f7e537f4a1ca4bbce7"
ref: "992f8062618ef1e78ee92efc7a709eb0d476e1d0"
resolved-ref: "992f8062618ef1e78ee92efc7a709eb0d476e1d0"
url: "https://github.com/LinwoodDev/dart_pkgs"
source: git
version: "1.0.0"
Expand Down Expand Up @@ -609,8 +609,8 @@ packages:
dependency: "direct main"
description:
path: "packages/material_leap"
ref: "7466e9723fa1cd802baa508b8b4ee4a54cb53dc2"
resolved-ref: "7466e9723fa1cd802baa508b8b4ee4a54cb53dc2"
ref: "40c3fd31b429269344f64f7c8a7b6118da5cac31"
resolved-ref: "40c3fd31b429269344f64f7c8a7b6118da5cac31"
url: "https://github.com/LinwoodDev/dart_pkgs"
source: git
version: "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dependencies:
material_leap:
git:
url: https://github.com/LinwoodDev/dart_pkgs
ref: 7466e9723fa1cd802baa508b8b4ee4a54cb53dc2
ref: 40c3fd31b429269344f64f7c8a7b6118da5cac31
path: packages/material_leap
phosphor_flutter:
git:
Expand Down

0 comments on commit 240b893

Please sign in to comment.