Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions lib/database/powersync/database.g.dart

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

2 changes: 2 additions & 0 deletions lib/database/powersync/tables/routines.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class WorkoutLogTable extends Table {
RealColumn get weight => real().nullable()();
RealColumn get weightTarget => real().nullable().named('weight_target')();
IntColumn get weightUnitId => integer().nullable().named('weight_unit_id')();
TextColumn get notes => text().nullable()();

DateTimeColumn get date => dateTime().map(const UtcDateTimeConverter())();
}
Expand All @@ -100,6 +101,7 @@ const PowersyncWorkoutLogTable = ps.Table(
ps.Column.real('weight'),
ps.Column.real('weight_target'),
ps.Column.integer('weight_unit_id'),
ps.Column.text('notes'),
ps.Column.text('date'),
],
indexes: [
Expand Down
6 changes: 6 additions & 0 deletions lib/features/routines/models/log.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class Log {
num? rir;
num? rirTarget;

String? notes;

num? repetitions;
num? repetitionsTarget;
int? repetitionsUnitId;
Expand All @@ -95,6 +97,7 @@ class Log {
this.repetitionsUnitObj,
this.rir,
this.rirTarget,
this.notes,
this.weight,
this.weightTarget,
this.weightUnitId = WEIGHT_UNIT_KG,
Expand Down Expand Up @@ -134,6 +137,7 @@ class Log {
int? slotEntryId,
num? rir,
num? rirTarget,
String? notes,
num? repetitions,
num? repetitionsTarget,
int? repetitionsUnitId,
Expand All @@ -157,6 +161,7 @@ class Log {
repetitionsUnitObj: repetitionsUnitObj ?? this.repetitionsUnitObj,
rir: rir ?? this.rir,
rirTarget: rirTarget ?? this.rirTarget,
notes: notes ?? this.notes,
weight: weight ?? this.weight,
weightTarget: weightTarget ?? this.weightTarget,
weightUnitId: weightUnitId ?? this.weightUnitId,
Expand Down Expand Up @@ -208,6 +213,7 @@ class Log {
? drift.Value(weightTarget!.toDouble())
: const drift.Value.absent(),
weightUnitId: weightUnitId != null ? drift.Value(weightUnitId) : const drift.Value.absent(),
notes: notes != null ? drift.Value(notes) : const drift.Value.absent(),
date: drift.Value(date),
);
}
Expand Down
6 changes: 6 additions & 0 deletions lib/features/routines/providers/gym_log_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,10 @@ class GymLogNotifier extends _$GymLogNotifier {
void setWeightUnit(WeightUnit weightUnit) {
state = state?.copyWith(weightUnitObj: weightUnit);
}

void setNotes(String notes) {
if (state != null) {
state = state!..notes = notes;
}
}
}
23 changes: 22 additions & 1 deletion lib/features/routines/widgets/gym_mode/log_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,11 @@ class LogsPastLogsWidget extends ConsumerWidget {
return ListTile(
key: ValueKey('past-log-${pastLog.id}'),
title: Text(pastLog.repTextNoNl(context)),
subtitle: Text(dateFormat.format(pastLog.date)),
subtitle: Text(
pastLog.notes != null && pastLog.notes!.isNotEmpty
? '${dateFormat.format(pastLog.date)} · ${pastLog.notes}'
: dateFormat.format(pastLog.date),
),
trailing: const Icon(Icons.copy),
onTap: () {
logProvider.setLog(pastLog, exercise: exercise);
Expand Down Expand Up @@ -297,6 +301,13 @@ class LogFormWidget extends ConsumerStatefulWidget {

class _LogFormWidgetState extends ConsumerState<LogFormWidget> {
final _form = GlobalKey<FormState>();
final _notesController = TextEditingController();

@override
void dispose() {
_notesController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -368,6 +379,16 @@ class _LogFormWidgetState extends ConsumerState<LogFormWidget> {
log.rir = value == '' ? null : num.parse(value);
},
),
TextFormField(
key: const ValueKey('notes-input-widget'),
controller: _notesController,
decoration: InputDecoration(labelText: i18n.notes),
maxLines: 2,
keyboardType: TextInputType.multiline,
onChanged: (value) {
ref.read(gymLogProvider.notifier).setNotes(value);
},
),
FilledButton(
key: const ValueKey('save-log-button'),
onPressed: () async {
Expand Down
20 changes: 20 additions & 0 deletions lib/features/routines/widgets/logs/log_edit_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class _LogEditDialogState extends ConsumerState<LogEditDialog> {
num? _rir;
RepetitionUnit? _repetitionUnit;
WeightUnit? _weightUnit;
late TextEditingController _notesController;

bool _saving = false;

Expand All @@ -79,6 +80,13 @@ class _LogEditDialogState extends ConsumerState<LogEditDialog> {
_rir = widget.log.rir;
_repetitionUnit = widget.log.repetitionsUnitObj;
_weightUnit = widget.log.weightUnitObj;
_notesController = TextEditingController(text: widget.log.notes ?? '');
}

@override
void dispose() {
_notesController.dispose();
super.dispose();
}

Future<void> _onSave() async {
Expand All @@ -101,12 +109,14 @@ class _LogEditDialogState extends ConsumerState<LogEditDialog> {

setState(() => _saving = true);

final notes = _notesController.text.trim();
final updated = widget.log.copyWith(
repetitions: _repetitions,
weight: _weight,
rir: _rir,
repetitionsUnitObj: _repetitionUnit,
weightUnitObj: _weightUnit,
notes: notes.isEmpty ? null : notes,
);

try {
Expand Down Expand Up @@ -167,6 +177,16 @@ class _LogEditDialogState extends ConsumerState<LogEditDialog> {
_rir = v.isEmpty ? null : num.parse(v);
}),
),
const SizedBox(height: 12),
TextFormField(
key: const ValueKey('edit-notes-widget'),
controller: _notesController,
decoration: InputDecoration(
labelText: AppLocalizations.of(context).notes,
),
maxLines: 2,
keyboardType: TextInputType.multiline,
),
],
),
),
Expand Down
Loading