From 33ecfce313f1fb788c0f398bb3e8743d7bc14baa Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Wed, 29 Apr 2026 22:36:33 +0000 Subject: [PATCH] Use RMO publicreport store in compliance and district report creation --- ts/rmo/store/publicreport.ts | 29 ++++++++++++----------------- ts/rmo/view/ComplianceDistrict.vue | 2 +- ts/rmo/view/ComplianceMailer.vue | 2 +- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/ts/rmo/store/publicreport.ts b/ts/rmo/store/publicreport.ts index 5f4a9f3c..91bd0d74 100644 --- a/ts/rmo/store/publicreport.ts +++ b/ts/rmo/store/publicreport.ts @@ -13,25 +13,25 @@ export const useStorePublicReport = defineStore("publicreport", () => { // State const _byID = ref>(new Map()); const loading = ref(false); - //const ongoingFetch = ref | null>(null); + const ongoingFetches = ref | null>>( + new Map(), + ); function add(pr: PublicReport) { _byID.value.set(pr.public_id, pr); } - // Actions async function byID(id: string): Promise { - const r = _byID.value.get(id); - if (r) { - return r; - } - return fetchByID(id); + const uri = "/api/rmo/publicreport/" + id; + return byURI(uri); } async function byURI(uri: string): Promise { - const id = uri.split("/").pop() || ""; - if (!id) { - throw new Error(`${uri} is not a recognized public report URI`); - } - return byID(id); + let ongoing = ongoingFetches.value.get(uri); + if (ongoing) return ongoing; + ongoing = fetchByURI(uri).finally(() => { + ongoingFetches.value.set(uri, null); + }); + ongoingFetches.value.set(uri, ongoing); + return ongoing; } async function createCompliance( data: PublicReportComplianceCreateRequest, @@ -44,10 +44,6 @@ export const useStorePublicReport = defineStore("publicreport", () => { _byID.value.set(result.public_id, result); return result; } - async function fetchByID(id: string): Promise { - const uri = `/api/rmo/publicreport/${id}`; - return fetchByURI(uri); - } async function fetchByURI(uri: string): Promise { loading.value = true; try { @@ -73,7 +69,6 @@ export const useStorePublicReport = defineStore("publicreport", () => { byID, byURI, createCompliance, - fetchByID, fetchByURI, update, }; diff --git a/ts/rmo/view/ComplianceDistrict.vue b/ts/rmo/view/ComplianceDistrict.vue index dcc9e8b4..ec700da1 100644 --- a/ts/rmo/view/ComplianceDistrict.vue +++ b/ts/rmo/view/ComplianceDistrict.vue @@ -8,7 +8,7 @@ import { useRouter } from "vue-router"; import { useStoreDistrict } from "@/rmo/store/district"; import { useStoreLocal } from "@/store/local"; -import { useStorePublicReport } from "@/store/publicreport"; +import { useStorePublicReport } from "@/rmo/store/publicreport"; import PublicReportLoading from "@/rmo/components/PublicReportLoading.vue"; import { type District } from "@/type/api"; diff --git a/ts/rmo/view/ComplianceMailer.vue b/ts/rmo/view/ComplianceMailer.vue index 7900f4b0..f5fce37d 100644 --- a/ts/rmo/view/ComplianceMailer.vue +++ b/ts/rmo/view/ComplianceMailer.vue @@ -8,7 +8,7 @@ import { useRouter } from "vue-router"; import { useStoreDistrict } from "@/rmo/store/district"; import { useStoreLocal } from "@/store/local"; -import { useStorePublicReport } from "@/store/publicreport"; +import { useStorePublicReport } from "@/rmo/store/publicreport"; import PublicReportLoading from "@/rmo/components/PublicReportLoading.vue"; interface Props {