Skip to content

Commit

Permalink
feat(status): sync status after entity creation, entity status update…
Browse files Browse the repository at this point in the history
… logic change
  • Loading branch information
NSUWAL123 committed Mar 4, 2025
1 parent dc51b06 commit 1e78754
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/mapper/src/routes/[projectId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,17 @@
});
$effect(() => {
entitiesStore.syncEntityStatus(data.projectId);
});
$effect(() => {
entitiesStore.entitiesList;
let entityStatusStream: ShapeStream | undefined;
if (entitiesStore.entitiesList?.length === 0) return;
async function getEntityStatus() {
const entityStatusResponse = await fetch(`${API_URL}/projects/${data.projectId}/entities/statuses`, {
credentials: 'include',
});
const response = await entityStatusResponse.json();
entityStatusStream = getEntityStatusStream(data.projectId);
await entitiesStore.subscribeToEntityStatusUpdates(entityStatusStream, response);
await entitiesStore.subscribeToEntityStatusUpdates(entityStatusStream, entitiesStore.entitiesList);
}
getEntityStatus();
Expand Down
8 changes: 7 additions & 1 deletion src/mapper/src/store/entities.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ let entityToNavigate: entityIdCoordinateMapType | null = $state(null);
let toggleGeolocation: boolean = $state(false);
let createEntityLoading: boolean = $state(false);
let createGeomRecordLoading: boolean = $state(false);
let entitiesList: entitiesListType[] = $state([]);
let alertStore = getAlertStore();

function getEntityStatusStream(projectId: number): ShapeStream | undefined {
Expand Down Expand Up @@ -134,9 +135,11 @@ function getEntitiesStatusStore() {
async function syncEntityStatus(projectId: number) {
try {
syncEntityStatusLoading = true;
await fetch(`${API_URL}/projects/${projectId}/entities/statuses`, {
const entityStatusResponse = await fetch(`${API_URL}/projects/${projectId}/entities/statuses`, {
credentials: 'include',
});
const response = await entityStatusResponse.json();
entitiesList = response;
syncEntityStatusLoading = false;
} catch (error) {
syncEntityStatusLoading = false;
Expand Down Expand Up @@ -271,6 +274,9 @@ function getEntitiesStatusStore() {
get createGeomRecordLoading() {
return createGeomRecordLoading;
},
get entitiesList() {
return entitiesList;
},
};
}

Expand Down

0 comments on commit 1e78754

Please sign in to comment.