Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: menu duplication #33

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 51 additions & 45 deletions web/src/components/menu/Outfits.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,67 @@
import IconPlus from '@components/icons/IconPlus.svelte';
import IconImport from '@components/icons/IconImport.svelte';
let renameIndex: number = -1;
let renameLabel: string = '';
let deleteIndex: number = -1;
let isAdding: boolean = false;
let isJobAdding: boolean = false;
let isImporting: boolean = false;
let newOutfitLabel: string = '';
let newOutfitJobRank: number = 0;
let importOutfitId: number;
const handleRename = (index: number) => {
if (renameLabel.length > 0) {
$OUTFITS[index].label = renameLabel;
renameIndex = -1;
OUTFITS.edit($OUTFITS[index]);
}
};
const handleOutfitAction = (
action: string,
index: number,
outfit = null,
) => {
switch (action) {
case 'use':
OUTFITS.use(outfit);
break;
case 'share':
OUTFITS.share(index);
break;
case 'item':
OUTFITS.item(outfit, renameLabel);
break;
case 'delete':
OUTFITS.delete(index);
break;
}
};
const resetNewOutfitFields = () => {
isAdding = false;
isJobAdding = false;
newOutfitLabel = '';
newOutfitJobRank = 0;
};
const resetImportFields = () => {
isImporting = false;
importOutfitId = null;
};
</script>

{#each $OUTFITS as { label, outfit, id, jobname }, i}

<Wrapper label={jobname ? `${label} | JOB` : label}>
<svelte:fragment slot="extra_primary">
<Dropdown display="Options">
<div
class="w-full flex items-center justify-center gap-[0.5vh] h-[3vh]"
>
<button
on:click={() => {
OUTFITS.use(outfit);
}}
on:click={() => handleOutfitAction('use', outfit)}
class="btn w-full">{$LOCALE.USE_TITLE}</button
>
<button
Expand All @@ -48,17 +83,13 @@
{#if !jobname}
<button
disabled={jobname != null && !$JOBDATA.isBoss}
on:click={() => {
OUTFITS.share(id);
}}
on:click={() => handleOutfitAction('share', id)}
class="btn w-full"
>{$LOCALE.SHAREOUTFIT_TITLE}</button
>
{/if}
<button
on:click={() => {
OUTFITS.item(outfit, label);
}}
on:click={() => handleOutfitAction('item', outfit)}
class="btn w-full">{$LOCALE.ITEMOUTFIT_TITLE}</button
>
<button
Expand Down Expand Up @@ -91,13 +122,7 @@
<IconCancel />
</button>
<button
on:click={() => {
if (renameLabel.length > 0) {
$OUTFITS[i].label = renameLabel;
renameIndex = -1;
OUTFITS.edit($OUTFITS[i]);
}
}}
on:click={() => handleRename(i)}
class="btn h-full aspect-square p-[0.5vh]"
>
<IconCheck />
Expand All @@ -115,18 +140,15 @@
on:click={() => (deleteIndex = -1)}
>{$LOCALE.CANCEL_TITLE}</button
>

<button
class="btn w-full h-full"
on:click={() => {
OUTFITS.delete(id);
}}>{$LOCALE.CONFIRMREM_SUBTITLE}</button
on:click={() => handleOutfitAction('delete', id)}
>{$LOCALE.CONFIRMREM_SUBTITLE}</button
>
</div>
{/if}
</Dropdown>
</svelte:fragment>

<Divider />
</Wrapper>
{:else}
Expand Down Expand Up @@ -157,17 +179,11 @@
/>
{/if}
<button
on:click={() => {
isAdding = false;
isJobAdding = false;
newOutfitLabel = '';
newOutfitJobRank = 0;
}}
on:click={resetNewOutfitFields}
class="btn h-full aspect-square p-[0.5vh]"
>
<IconCancel />
</button>

<button
on:click={() => {
if (newOutfitLabel.length > 0) {
Expand All @@ -180,10 +196,7 @@
}
: null,
);
isAdding = false;
isJobAdding = false;
newOutfitLabel = '';
newOutfitJobRank = 0;
resetNewOutfitFields();
}
}}
class="btn h-full aspect-square p-[0.5vh]"
Expand All @@ -208,10 +221,7 @@
bind:value={importOutfitId}
/>
<button
on:click={() => {
isImporting = false;
importOutfitId = null;
}}
on:click={resetImportFields}
class="btn h-full aspect-square p-[0.5vh]"
>
<IconCancel />
Expand All @@ -220,8 +230,7 @@
on:click={() => {
if (importOutfitId > 0) {
OUTFITS.import(importOutfitId);
isImporting = false;
importOutfitId = null;
resetImportFields();
}
}}
class="btn h-full aspect-square p-[0.5vh]"
Expand All @@ -243,7 +252,6 @@
<div class="h-[60%] aspect-square grid place-items-center">
<IconPlus />
</div>

<p>{$LOCALE.ADDOUTFIT_TITLE}</p>
</button>

Expand All @@ -258,7 +266,6 @@
<div class="h-[60%] aspect-square grid place-items-center">
<IconPlus />
</div>

<p>{$LOCALE.ADDJOBOUTFIT}</p>
</button>
{/if}
Expand All @@ -273,7 +280,6 @@
<div class="h-[60%] aspect-square grid place-items-center">
<IconImport />
</div>

<p>{$LOCALE.IMPORTOUTFIT_TITLE}</p>
</button>
{/if}
Expand Down
Loading