How to fetch new info from database without closing mounted components

Viewed 25

I`ve been working in a Svelte SaaS recently and there is an mobile app that updates my db constantly, so then I need to fetch info from db again every 1 minute.

The problem is: Inside some hierarchical components, I have modals that close whenever I update my promise. Is there something that can be done so my user doesn`t need to reopen the modal?

Here is the code that updates my promise ( finishedPromise )

    onMount(async () => {
        const depots = await depotsPromise;
        depots.forEach(depot=> checkedDepots.add(depot._id));
        toRouteFilter = toRouteFilter;
        let isOnline = setInterval(() => {
            DataStorage.get('finished',true).then(finisheds=> finishedPromise = Promise.resolve(finisheds));
        }, 60*1000);
        return function(){
            clearInterval(isOnline);
        }
    });

Rendering the components:

  <div>
    {#await filteredRoutes}
        Carregando...
    {:then routes}
        {#if selectedTab == 1}
            <ManageDelivery
                routes={routes}/>
        {:else}
            <MapDelivery />
        {/if}
    {/await}
  </div>

My modals are rendered inside the component ManageDelivery, only by using a local inside flag of showModal as true or false.

0 Answers
Related