servicesOfJournal function Providers

  1. @Riverpod(keepAlive: true)
Map<ServiceState, List<ServiceOfJournal>> servicesOfJournal(
  1. Ref<Object?> ref,
  2. Journal journal
)

Provider of groups of ServiceOfJournal sorted by ServiceState.

Implementation

@Riverpod(keepAlive: true)
Map<ServiceState, List<ServiceOfJournal>> servicesOfJournal(
    Ref ref, Journal journal) {
  if (journal.aData == null) {
    final journalServices =
        ref.watch(hiveRepositoryProvider(journal.worker.apiKey));

    return groupBy<ServiceOfJournal, ServiceState>(
      journalServices,
      (e) => e.state,
    );
  } else {
    final journalServices =
        ref.watch(archiveReaderProvider(journal.worker.apiKey));

    return groupBy<ServiceOfJournal, ServiceState>(
      journalServices.where((e) => e.provDate.dateOnly() == journal.aData),
      (e) => e.state,
    );
  }
}