Use RMO publicreport store in compliance and district report creation

This commit is contained in:
Eli Ribble 2026-04-29 22:36:33 +00:00
parent 9229725300
commit 33ecfce313
No known key found for this signature in database
3 changed files with 14 additions and 19 deletions

View file

@ -13,25 +13,25 @@ export const useStorePublicReport = defineStore("publicreport", () => {
// State
const _byID = ref<Map<string, PublicReport>>(new Map());
const loading = ref(false);
//const ongoingFetch = ref<Promise<PublicReport[]> | null>(null);
const ongoingFetches = ref<Map<string, Promise<PublicReport> | null>>(
new Map(),
);
function add(pr: PublicReport) {
_byID.value.set(pr.public_id, pr);
}
// Actions
async function byID(id: string): Promise<PublicReport> {
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<PublicReport> {
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<PublicReport> {
const uri = `/api/rmo/publicreport/${id}`;
return fetchByURI(uri);
}
async function fetchByURI(uri: string): Promise<PublicReport> {
loading.value = true;
try {
@ -73,7 +69,6 @@ export const useStorePublicReport = defineStore("publicreport", () => {
byID,
byURI,
createCompliance,
fetchByID,
fetchByURI,
update,
};

View file

@ -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";

View file

@ -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 {