Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/LinwoodCloud/Flow into d…
Browse files Browse the repository at this point in the history
…evelop
  • Loading branch information
CodeDoctorDE committed Oct 31, 2023
2 parents 1b903a3 + 61275a8 commit 31c6647
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 96 deletions.
11 changes: 10 additions & 1 deletion app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -270,5 +270,14 @@
},
"deleteLabelDescription": "Are you sure you want to delete the label {name}?",
"label": "Label",
"startOfWeek": "Start of week"
"startOfWeek": "Start of week",
"headlineNumber": "Headline {number}",
"@headlineNumber": {
"placeholders": {
"number": {
"type": "int",
"example": "1"
}
}
}
}
39 changes: 16 additions & 23 deletions app/lib/pages/calendar/item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,32 +213,25 @@ class _CalendarItemDialogState extends State<CalendarItemDialog> {
},
),
const SizedBox(height: 16),
DropdownButtonFormField<EventStatus>(
value: _item.status,
items: EventStatus.values
.map<DropdownMenuItem<EventStatus>>((value) {
return DropdownMenuItem<EventStatus>(
value: value,
child: Row(
children: [
PhosphorIcon(
value.icon(PhosphorIconsStyle.light),
color: value.getColor()),
const SizedBox(width: 8),
Text(value.getLocalizedName(context)),
],
),
);
}).toList(),
onChanged: (EventStatus? value) {
DropdownMenu<EventStatus>(
initialSelection: _item.status,
dropdownMenuEntries: EventStatus.values
.map((value) => DropdownMenuEntry<EventStatus>(
value: value,
leadingIcon: PhosphorIcon(
value.icon(PhosphorIconsStyle.light),
color: value.getColor()),
label: value.getLocalizedName(context),
))
.toList(),
onSelected: (EventStatus? value) {
_item =
_item.copyWith(status: value ?? _item.status);
},
decoration: InputDecoration(
labelText: AppLocalizations.of(context).status,
icon: const PhosphorIcon(PhosphorIconsLight.info),
border: const OutlineInputBorder(),
),
label: Text(AppLocalizations.of(context).status),
leadingIcon:
const PhosphorIcon(PhosphorIconsLight.info),
expandedInsets: const EdgeInsets.all(4),
),
const SizedBox(height: 16),
TextFormField(
Expand Down
51 changes: 49 additions & 2 deletions app/lib/pages/notes/card.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,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';
Expand Down Expand Up @@ -36,8 +39,10 @@ class NoteCard extends StatefulWidget {
State<NoteCard> createState() => _NoteCardState();
}

enum PastePositing { line, selection }

class _NoteCardState extends State<NoteCard> {
late final TextEditingController _nameController;
late final TextEditingController _nameController, _descriptionController;
late Note _newNote;
late final FlowCubit _cubit;
late final SourceService _sourceService;
Expand All @@ -52,6 +57,8 @@ class _NoteCardState extends State<NoteCard> {
void initState() {
super.initState();
_nameController = TextEditingController(text: widget.note.name);
_descriptionController =
TextEditingController(text: widget.note.description);
_newNote = widget.note;
_cubit = context.read<FlowCubit>();
_sourceService = _cubit.getService(widget.source);
Expand Down Expand Up @@ -85,6 +92,26 @@ class _NoteCardState extends State<NoteCard> {
}
}

void _addDescription(PastePositing position, String text) {
var description = _descriptionController.text;
final selection = _descriptionController.selection;
if (!selection.isValid) return;
final start = selection.baseOffset;
final lineStart = max(0, description.lastIndexOf("\n", start));
description = switch (position) {
PastePositing.line => description.substring(0, lineStart) +
text +
description.substring(lineStart),
PastePositing.selection => description.substring(0, start) +
text +
description.substring(selection.extentOffset),
};
_descriptionController.text = description;
_descriptionController.selection = TextSelection.collapsed(
offset: start + text.length,
);
}

@override
Widget build(BuildContext context) {
return Card(
Expand Down Expand Up @@ -302,12 +329,32 @@ class _NoteCardState extends State<NoteCard> {
]),
),
const SizedBox(height: 16),
if (widget.primary)
SizedBox(
height: 50,
child: ListView(scrollDirection: Axis.horizontal, children: [
...[
PhosphorIconsLight.textHOne,
PhosphorIconsLight.textHTwo,
PhosphorIconsLight.textHThree,
PhosphorIconsLight.textHFour,
PhosphorIconsLight.textHFive,
PhosphorIconsLight.textHSix
].mapIndexed((index, element) => IconButton(
icon: PhosphorIcon(element),
onPressed: () => _addDescription(
PastePositing.line,
"${"#" * (index + 1)} ",
),
))
]),
),
MarkdownField(
decoration: InputDecoration(
labelText: AppLocalizations.of(context).description,
border: const OutlineInputBorder(),
),
value: _newNote.description,
controller: _descriptionController,
onChangeEnd: (value) {
_newNote = _newNote.copyWith(description: value);
_updateNote();
Expand Down
59 changes: 35 additions & 24 deletions app/lib/pages/notes/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,13 @@ class NotesBodyView extends StatefulWidget {
class _NotesBodyViewState extends State<NotesBodyView> {
late final FlowCubit _flowCubit;
late final SourcedPagingController<Note> _controller;
late final Future<Note?> _parent;
late NoteFilter _filter;

@override
void initState() {
_flowCubit = context.read<FlowCubit>();
_parent = _fetchParent();
_controller = SourcedPagingController(_flowCubit);
_controller.addFetchListener((source, service, offset, limit) async {
if (_filter.source != null && _filter.source != source) return null;
Expand All @@ -177,17 +179,21 @@ class _NotesBodyViewState extends State<NotesBodyView> {
search: widget.search);
if (notes == null) return null;
if (source != widget.parent?.source) return notes;
final parent = await service.note?.getNote(widget.parent!.model);
if (parent == null) return notes;
return [
parent,
...notes,
];
return notes;
});
_filter = widget.filter;
super.initState();
}

Future<Note?> _fetchParent() async {
if (widget.parent == null) return null;
final parent = await _flowCubit
.getService(widget.parent!.source)
.note
?.getNote(widget.parent!.model);
return parent;
}

@override
void dispose() {
_controller.dispose();
Expand All @@ -214,6 +220,24 @@ class _NotesBodyViewState extends State<NotesBodyView> {
return Scaffold(
body: Column(
children: [
FutureBuilder<Note?>(
future: _parent,
builder: (context, snapshot) {
final data = snapshot.data;
if (data == null) return Container();
return Column(
children: [
NoteCard(
controller: _controller,
source: widget.parent!.source,
primary: true,
note: data,
),
const SizedBox(height: 8),
const Divider(),
],
);
}),
NoteFilterView(
initialFilter: _filter,
onChanged: (filter) {
Expand All @@ -229,24 +253,11 @@ class _NotesBodyViewState extends State<NotesBodyView> {
pagingController: _controller,
builderDelegate: buildMaterialPagedDelegate<SourcedModel<Note>>(
_controller,
(ctx, item, index) {
final primary = item.source == widget.parent?.source &&
item.model.id == widget.parent?.model;
return Column(
children: [
NoteCard(
controller: _controller,
source: item.source,
note: item.model,
primary: primary,
),
if (primary) ...[
const SizedBox(height: 8),
const Divider(),
]
],
);
},
(ctx, item, index) => NoteCard(
controller: _controller,
source: item.source,
note: item.model,
),
),
),
),
Expand Down
13 changes: 8 additions & 5 deletions app/lib/widgets/markdown_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import 'package:url_launcher/url_launcher_string.dart';
import 'package:markdown/markdown.dart' as md;

class MarkdownField extends StatefulWidget {
final String value;
final String? value;
final InputDecoration decoration;
final TextEditingController? controller;
final ValueChanged<String>? onChanged, onChangeEnd;
final List<Widget> actions;

const MarkdownField(
{super.key,
required this.value,
this.value,
this.controller,
this.onChanged,
this.onChangeEnd,
this.decoration = const InputDecoration(),
Expand All @@ -23,14 +25,15 @@ class MarkdownField extends StatefulWidget {
}

class _MarkdownFieldState extends State<MarkdownField> {
final TextEditingController _controller = TextEditingController();
late final TextEditingController _controller;
bool _editMode = false;
final FocusNode _focusNode = FocusNode();

@override
void initState() {
super.initState();
_controller.text = widget.value;
_controller =
widget.controller ?? TextEditingController(text: widget.value);
_focusNode.addListener(() {
if (!_focusNode.hasFocus) {
_exitEditMode();
Expand All @@ -42,7 +45,7 @@ class _MarkdownFieldState extends State<MarkdownField> {
void didUpdateWidget(MarkdownField oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.value != widget.value) {
_controller.text = widget.value;
_controller.text = widget.value ?? _controller.text;
}
}

Expand Down
28 changes: 9 additions & 19 deletions app/lib/widgets/source_dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,19 @@ class SourceDropdown<T> extends StatelessWidget {
})
.whereNotNull()
.toList());
final remotes = services.keys.map((e) => cubit.sourcesService.getRemote(e));
return Column(
children: [
const SizedBox(height: 16),
DropdownButtonFormField<String>(
value: value,
items: services.entries.map<DropdownMenuItem<String>>((value) {
DropdownMenu<String>(
initialSelection: value,
dropdownMenuEntries: services.entries.map((value) {
final remote = cubit.sourcesService.getRemote(value.key);
return DropdownMenuItem<String>(
return DropdownMenuEntry<String>(
value: value.key,
child: Text(
remote?.displayName ?? AppLocalizations.of(context).local),
label: remote?.displayName ?? AppLocalizations.of(context).local,
);
}).toList(),
selectedItemBuilder: (context) {
return [
...remotes.map<Widget>((value) =>
Text(value?.uri.host ?? AppLocalizations.of(context).local))
];
},
onChanged: (value) {
onSelected: (value) {
final service = services[value];
onChanged(
service == null
Expand All @@ -64,11 +56,9 @@ class SourceDropdown<T> extends StatelessWidget {
),
);
},
decoration: InputDecoration(
labelText: AppLocalizations.of(context).source,
icon: const PhosphorIcon(PhosphorIconsLight.cloud),
border: const OutlineInputBorder(),
),
label: Text(AppLocalizations.of(context).source),
leadingIcon: const PhosphorIcon(PhosphorIconsLight.cloud),
expandedInsets: const EdgeInsets.all(4),
),
],
);
Expand Down
Loading

0 comments on commit 31c6647

Please sign in to comment.