serviceState function Data Models

  1. @riverpod
ClientServiceState serviceState(
  1. Ref<Object?> ref,
  2. ClientService client
)

Model for ServiceCard and other widget.

This is mostly a view model for data from:

Implementation

@riverpod
ClientServiceState serviceState(Ref ref, ClientService client) {
  final journal = ref.watch(journalProvider(client.apiKey));
  final jServ = ref.watch(jServicesOfClientProvider(client));

  return ClientServiceState(
    client: client,
    ref: ref,
    isReadOnly: journal.state.isArchive,
    added: jServ[ServiceState.added]!.length,
    rejected: jServ[ServiceState.rejected]!.length,
    left: client.plan -
        client.filled -
        jServ[ServiceState.added]!.length -
        jServ[ServiceState.finished]!.length,
    // but not outDated
    done: jServ[ServiceState.finished]!.length +
        jServ[ServiceState.outDated]!.length,
  );
}