Skip to content

Commit

Permalink
feat: assign category on entry creation
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasn committed Jan 23, 2025
1 parent 890e6f2 commit 2255ef3
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 35 deletions.
3 changes: 2 additions & 1 deletion lib/beamer/locations/journal_location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class JournalLocation extends BeamLocation<BeamState> {

final entryId = state.pathParameters['entryId'];
final linkedId = state.pathParameters['linkedId'];
final categoryId = state.queryParameters['categoryId'];

return [
const BeamPage(
Expand All @@ -46,7 +47,7 @@ class JournalLocation extends BeamLocation<BeamState> {
if (pathContains('record_audio/'))
BeamPage(
key: ValueKey('record_audio-$linkedId'),
child: RecordAudioPage(linkedId: linkedId),
child: RecordAudioPage(linkedId: linkedId, categoryId: categoryId),
),
];
}
Expand Down
3 changes: 2 additions & 1 deletion lib/beamer/locations/tasks_location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class TasksLocation extends BeamLocation<BeamState> {

final entryId = state.pathParameters['entryId'];
final linkedId = state.pathParameters['linkedId'];
final categoryId = state.queryParameters['categoryId'];

return [
const BeamPage(
Expand All @@ -36,7 +37,7 @@ class TasksLocation extends BeamLocation<BeamState> {
if (pathContains('record_audio/'))
BeamPage(
key: ValueKey('record_audio-$linkedId'),
child: RecordAudioPage(linkedId: linkedId),
child: RecordAudioPage(linkedId: linkedId, categoryId: categoryId),
),
];
}
Expand Down
3 changes: 1 addition & 2 deletions lib/features/dashboards/state/chart_scale_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class BarWidthController extends _$BarWidthController {
}

void updateScale(Matrix4 scale) {
final scaleX = scale.row0.x;
state = scaleX.floorToDouble();
state = scale.row0.x;
}
}
8 changes: 7 additions & 1 deletion lib/features/journal/repository/journal_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,17 @@ class JournalRepository {
required DateTime started,
required String id,
String? linkedId,
String? categoryId,
}) async {
try {
final persistenceLogic = getIt<PersistenceLogic>();

final journalEntity = JournalEntity.journalEntry(
entryText: entryText,
meta: await persistenceLogic.createMetadata(dateFrom: started),
meta: await persistenceLogic.createMetadata(
dateFrom: started,
categoryId: categoryId,
),
);

await persistenceLogic.createDbEntity(journalEntity, linkedId: linkedId);
Expand All @@ -154,6 +158,7 @@ class JournalRepository {
static Future<JournalEntity?> createImageEntry(
ImageData imageData, {
String? linkedId,
String? categoryId,
}) async {
try {
final persistenceLogic = getIt<PersistenceLogic>();
Expand All @@ -165,6 +170,7 @@ class JournalRepository {
dateTo: imageData.capturedAt,
uuidV5Input: json.encode(imageData),
flag: EntryFlag.import,
categoryId: categoryId,
),
geolocation: imageData.geolocation,
);
Expand Down
28 changes: 14 additions & 14 deletions lib/features/journal/ui/pages/infinite_journal_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,27 @@ class InfiniteJournalPage extends StatelessWidget {
return BlocProvider<JournalPageCubit>(
create: (BuildContext context) => JournalPageCubit(showTasks: showTasks),
child: Scaffold(
floatingActionButton: showTasks
? BlocBuilder<JournalPageCubit, JournalPageState>(
builder: (context, snapshot) {
return FloatingAddIcon(
floatingActionButton: BlocBuilder<JournalPageCubit, JournalPageState>(
builder: (context, snapshot) {
final selectedCategoryIds = snapshot.selectedCategoryIds;
final categoryId = selectedCategoryIds.length == 1
? selectedCategoryIds.first
: null;

return showTasks
? FloatingAddIcon(
createFn: () async {
final selectedCategoryIds = snapshot.selectedCategoryIds;
final task = await createTask(
categoryId: selectedCategoryIds.length == 1
? selectedCategoryIds.first
: null,
);
final task = await createTask(categoryId: categoryId);
if (task != null) {
getIt<NavService>()
.beamToNamed('/tasks/${task.meta.id}');
}
},
semanticLabel: context.messages.addActionAddTask,
);
},
)
: const FloatingAddActionButton(),
)
: FloatingAddActionButton(categoryId: categoryId);
},
),
body: InfiniteJournalPageBody(
showTasks: showTasks,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import 'package:material_design_icons_flutter/material_design_icons_flutter.dart
class CreateTextEntryListTile extends StatelessWidget {
const CreateTextEntryListTile(
this.linkedFromId, {
this.categoryId,
super.key,
});

final String? linkedFromId;
final String? categoryId;

@override
Widget build(BuildContext context) {
Expand All @@ -23,7 +25,7 @@ class CreateTextEntryListTile extends StatelessWidget {
title: Text(context.messages.addActionAddText),
onTap: () {
Navigator.of(context).pop();
createTextEntry(linkedId: linkedFromId);
createTextEntry(linkedId: linkedFromId, categoryId: categoryId);
},
);
}
Expand All @@ -32,18 +34,20 @@ class CreateTextEntryListTile extends StatelessWidget {
class CreateScreenshotListTile extends StatelessWidget {
const CreateScreenshotListTile(
this.linkedFromId, {
this.categoryId,
super.key,
});

final String? linkedFromId;
final String? categoryId;

@override
Widget build(BuildContext context) {
return ListTile(
leading: Icon(MdiIcons.monitorScreenshot),
title: Text(context.messages.addActionAddScreenshot),
onTap: () {
createScreenshot(linkedId: linkedFromId);
createScreenshot(linkedId: linkedFromId, categoryId: categoryId);
Navigator.of(context).pop();
},
);
Expand Down Expand Up @@ -77,10 +81,12 @@ class CreateTimerListTile extends ConsumerWidget {
class CreateAudioRecordingListTile extends StatelessWidget {
const CreateAudioRecordingListTile(
this.linkedFromId, {
this.categoryId,
super.key,
});

final String? linkedFromId;
final String? categoryId;

@override
Widget build(BuildContext context) {
Expand All @@ -90,9 +96,15 @@ class CreateAudioRecordingListTile extends StatelessWidget {
onTap: () {
Navigator.of(context).pop();
if (getIt<NavService>().isTasksTabActive()) {
beamToNamed('/tasks/$linkedFromId/record_audio/$linkedFromId');
beamToNamed(
'/tasks/$linkedFromId/record_audio/$linkedFromId?categoryId=$categoryId',
data: {'categoryId': categoryId},
);
} else {
beamToNamed('/journal/$linkedFromId/record_audio/$linkedFromId');
beamToNamed(
'/journal/$linkedFromId/record_audio/$linkedFromId?categoryId=$categoryId',
data: {'categoryId': categoryId},
);
}
},
);
Expand Down Expand Up @@ -133,10 +145,12 @@ class CreateTaskListTile extends StatelessWidget {
class CreateEventListTile extends StatelessWidget {
const CreateEventListTile(
this.linkedFromId, {
this.categoryId,
super.key,
});

final String? linkedFromId;
final String? categoryId;

@override
Widget build(BuildContext context) {
Expand All @@ -148,6 +162,7 @@ class CreateEventListTile extends StatelessWidget {

final event = await createEvent(
linkedId: linkedFromId,
categoryId: categoryId,
);

if (event != null) {
Expand All @@ -161,10 +176,12 @@ class CreateEventListTile extends StatelessWidget {
class ImportImageAssetsListTile extends StatelessWidget {
const ImportImageAssetsListTile(
this.linkedFromId, {
this.categoryId,
super.key,
});

final String? linkedFromId;
final String? categoryId;

@override
Widget build(BuildContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ class CreateEntryModal {
title: context.messages.createEntryTitle,
builder: (_) => Column(
children: [
CreateEventListTile(linkedFromId),
CreateEventListTile(linkedFromId, categoryId: categoryId),
CreateTaskListTile(linkedFromId, categoryId: categoryId),
CreateAudioRecordingListTile(linkedFromId),
CreateAudioRecordingListTile(linkedFromId, categoryId: categoryId),
if (linkedFromId != null) CreateTimerListTile(linkedFromId),
CreateTextEntryListTile(linkedFromId),
ImportImageAssetsListTile(linkedFromId),
if (isMacOS) CreateScreenshotListTile(linkedFromId),
CreateTextEntryListTile(linkedFromId, categoryId: categoryId),
ImportImageAssetsListTile(linkedFromId, categoryId: categoryId),
if (isMacOS)
CreateScreenshotListTile(linkedFromId, categoryId: categoryId),
verticalModalSpacer,
],
),
Expand Down
2 changes: 2 additions & 0 deletions lib/features/speech/repository/speech_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SpeechRepository {
AudioNote audioNote, {
required String? language,
String? linkedId,
String? categoryId,
}) async {
try {
final persistenceLogic = getIt<PersistenceLogic>();
Expand Down Expand Up @@ -45,6 +46,7 @@ class SpeechRepository {
dateTo: dateTo,
uuidV5Input: json.encode(audioData),
flag: EntryFlag.import,
categoryId: categoryId,
),
);
await persistenceLogic.createDbEntity(journalEntity, linkedId: linkedId);
Expand Down
7 changes: 7 additions & 0 deletions lib/features/speech/state/recorder_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class AudioRecorderCubit extends Cubit<AudioRecorderState> {
final LoggingService _loggingService = getIt<LoggingService>();
final PersistenceLogic persistenceLogic = getIt<PersistenceLogic>();
String? _linkedId;
String? _categoryId;
String? _language;
AudioNote? _audioNote;

Expand Down Expand Up @@ -110,6 +111,7 @@ class AudioRecorderCubit extends Cubit<AudioRecorderState> {
_audioNote!,
language: _language,
linkedId: _linkedId,
categoryId: _categoryId,
);
_linkedId = null;
final entryId = journalAudio?.meta.id;
Expand Down Expand Up @@ -149,4 +151,9 @@ class AudioRecorderCubit extends Cubit<AudioRecorderState> {
await _audioRecorder.dispose();
await _amplitudeSub?.cancel();
}

// ignore: use_setters_to_change_properties
void setCategoryId(String? categoryId) {
_categoryId = categoryId;
}
}
10 changes: 9 additions & 1 deletion lib/features/speech/ui/pages/record_audio_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,24 @@ class RecordAudioPage extends StatelessWidget {
const RecordAudioPage({
super.key,
this.linkedId,
this.categoryId,
});

final String? linkedId;
final String? categoryId;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: TitleAppBar(title: context.messages.addAudioTitle),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [AudioRecorderWidget(linkedId: linkedId)],
children: [
AudioRecorderWidget(
linkedId: linkedId,
categoryId: categoryId,
),
],
),
);
}
Expand Down
5 changes: 4 additions & 1 deletion lib/features/speech/ui/widgets/audio_recorder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ class AudioRecorderWidget extends ConsumerWidget {
const AudioRecorderWidget({
super.key,
this.linkedId,
this.categoryId,
});

final String? linkedId;
final String? categoryId;

String formatDuration(String str) {
return str.substring(0, str.length - 7);
Expand All @@ -31,7 +33,8 @@ class AudioRecorderWidget extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
return BlocBuilder<AudioRecorderCubit, AudioRecorderState>(
builder: (context, state) {
final cubit = context.read<AudioRecorderCubit>();
final cubit = context.read<AudioRecorderCubit>()
..setCategoryId(categoryId);

Future<void> stop() async {
final entryId = await cubit.stop();
Expand Down
12 changes: 9 additions & 3 deletions lib/logic/create/create_entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import 'package:lotti/services/time_service.dart';
import 'package:lotti/utils/file_utils.dart';
import 'package:lotti/utils/screenshots.dart';

Future<JournalEntity?> createTextEntry({String? linkedId}) async {
Future<JournalEntity?> createTextEntry(
{String? linkedId, String? categoryId,}) async {
final entry = await JournalRepository.createTextEntry(
const EntryText(plainText: ''),
id: uuid.v1(),
linkedId: linkedId,
categoryId: categoryId,
started: DateTime.now(),
);

Expand Down Expand Up @@ -68,7 +70,7 @@ Future<Task?> createTask({String? linkedId, String? categoryId}) async {
return task;
}

Future<JournalEvent?> createEvent({String? linkedId}) =>
Future<JournalEvent?> createEvent({String? linkedId, String? categoryId}) =>
getIt<PersistenceLogic>().createEventEntry(
data: const EventData(
status: EventStatus.tentative,
Expand All @@ -77,9 +79,13 @@ Future<JournalEvent?> createEvent({String? linkedId}) =>
),
entryText: const EntryText(plainText: ''),
linkedId: linkedId,
categoryId: categoryId,
);

Future<JournalEntity?> createScreenshot({String? linkedId}) async {
Future<JournalEntity?> createScreenshot({
String? linkedId,
String? categoryId,
}) async {
final persistenceLogic = getIt<PersistenceLogic>();
final imageData = await takeScreenshotMac();
final entry = await JournalRepository.createImageEntry(
Expand Down
2 changes: 2 additions & 0 deletions lib/logic/image_import.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:wechat_assets_picker/wechat_assets_picker.dart';
Future<void> importImageAssets(
BuildContext context, {
String? linkedId,
String? categoryId,
}) async {
final assets = await AssetPicker.pickAssets(
context,
Expand Down Expand Up @@ -78,6 +79,7 @@ Future<void> importImageAssets(
await JournalRepository.createImageEntry(
imageData,
linkedId: linkedId,
categoryId: categoryId,
);
}
}
Expand Down
Loading

0 comments on commit 2255ef3

Please sign in to comment.