Skip to content

Commit

Permalink
dashboard client: align default value of campaigns store to the same …
Browse files Browse the repository at this point in the history
…as the rest (null)
  • Loading branch information
HolecekM committed Dec 17, 2024
1 parent 9011ef1 commit 7b35015
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
36 changes: 19 additions & 17 deletions dashboard/client/src/SideNavBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,25 @@
{/each}
</CollapsibleSection>

<CollapsibleSection id="campaignList" label="Campaigns">
{#each $campaigns as campaign}
<CollapsibleSection id={campaign.id} label={campaign.name} level={2}>
<span slot="labelExtra">
<span
role="button"
tabindex="0"
class="badge bg-black"
on:keypress={() => chooseCampaignDetail(campaign.id)}
on:click={() => chooseCampaignDetail(campaign.id)}
title="Show campaign details">i</span
>
</span>
<CampaignStepList id={campaign.id} />
</CollapsibleSection>
{/each}
</CollapsibleSection>
{#if $campaigns}
<CollapsibleSection id="campaignList" label="Campaigns">
{#each $campaigns as campaign}
<CollapsibleSection id={campaign.id} label={campaign.name} level={2}>
<span slot="labelExtra">
<span
role="button"
tabindex="0"
class="badge bg-black"
on:keypress={() => chooseCampaignDetail(campaign.id)}
on:click={() => chooseCampaignDetail(campaign.id)}
title="Show campaign details">i</span
>
</span>
<CampaignStepList id={campaign.id} />
</CollapsibleSection>
{/each}
</CollapsibleSection>
{/if}
</ul>
{/if}
</div>
Expand Down
2 changes: 1 addition & 1 deletion dashboard/client/src/campaigns/CampaignStepList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
export let id;
let root;
let campaign = derived([campaigns], ([campaigns]) => campaigns.find((camp) => camp.id === id));
let campaign = derived([campaigns], ([campaigns]) => campaigns?.find((camp) => camp.id === id));
const load = () => loadSingleCampaign(id).then();
Expand Down
4 changes: 2 additions & 2 deletions dashboard/client/src/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const chosenCampaignStep = derived([campaigns, path], ([campaigns, path])

const [, campaignId, stepId] = match;

const step = campaigns.find((camp) => camp.id === campaignId)?.steps?.find((step) => step.id === stepId) ?? null;
const step = campaigns?.find((camp) => camp.id === campaignId)?.steps?.find((step) => step.id === stepId) ?? null;
return step === null
? null
: {
Expand All @@ -52,5 +52,5 @@ export const chosenCampaignDetail = derived([campaigns, path], ([campaigns, path
const match = path.match(/^#campaign\/(.+)$/);
if (!match) return null;

return campaigns.find((camp) => camp.id === match[1]) ?? null;
return campaigns?.find((camp) => camp.id === match[1]) ?? null;
});
8 changes: 6 additions & 2 deletions dashboard/client/src/stores.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const isLoading = writable(false);

export const classes = writable(null);
export const challenges = writable(null);
export const campaigns = writable([]);
export const campaigns = writable(null);

export const storageBackedWritable = (key, defaultData) => {
const store = writable(localStorage.getItem(key) ?? defaultData);
Expand All @@ -26,7 +26,7 @@ export const storageBackedWritable = (key, defaultData) => {
export const loadSingleCampaign = async (id) => {
const campaign = await fetchSingleCampaign(id);
campaigns.update((old) => {
const neu = [...old];
const neu = old === null ? [] : [...old];
const index = neu.findIndex((camp) => camp.id === campaign.id);
neu[index] = {
...neu[index],
Expand All @@ -39,12 +39,16 @@ export const loadSingleCampaign = async (id) => {
export const setChallengeRunning = (challengeId, campaignId, running) => {
if (campaignId) {
campaigns.update((campaigns) => {
if (!campaigns) return campaigns;

campaigns.find((camp) => camp.id === campaignId).steps.find((chall) => chall.id === challengeId).running =
running;
return campaigns;
});
} else {
challenges.update((challs) => {
if (!challs) return challs;

challs.find((chall) => chall.id === challengeId).running = running;
return challs;
});
Expand Down

0 comments on commit 7b35015

Please sign in to comment.