mirror of
https://github.com/jcreek/LivingDexTracker.git
synced 2026-07-13 02:53:45 +00:00
fix(#63): Enforce mutually exclusive catch states
This commit is contained in:
@@ -32,6 +32,24 @@
|
|||||||
function updateCatchRecord() {
|
function updateCatchRecord() {
|
||||||
dispatch('updateCatch', { pokedexEntry, catchRecord });
|
dispatch('updateCatch', { pokedexEntry, catchRecord });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onCaughtChange() {
|
||||||
|
if (!catchRecord) return;
|
||||||
|
// Mutually exclusive with "needs to evolve"
|
||||||
|
if (catchRecord.caught) {
|
||||||
|
catchRecord.haveToEvolve = false;
|
||||||
|
}
|
||||||
|
updateCatchRecord();
|
||||||
|
}
|
||||||
|
|
||||||
|
function onNeedsToEvolveChange() {
|
||||||
|
if (!catchRecord) return;
|
||||||
|
// Mutually exclusive with "caught"
|
||||||
|
if (catchRecord.haveToEvolve) {
|
||||||
|
catchRecord.caught = false;
|
||||||
|
}
|
||||||
|
updateCatchRecord();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
@@ -84,7 +102,7 @@
|
|||||||
type="checkbox"
|
type="checkbox"
|
||||||
bind:checked={catchRecord.caught}
|
bind:checked={catchRecord.caught}
|
||||||
class="checkbox checkbox-primary border-black"
|
class="checkbox checkbox-primary border-black"
|
||||||
on:change={updateCatchRecord}
|
on:change={onCaughtChange}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
@@ -97,7 +115,7 @@
|
|||||||
type="checkbox"
|
type="checkbox"
|
||||||
bind:checked={catchRecord.haveToEvolve}
|
bind:checked={catchRecord.haveToEvolve}
|
||||||
class="checkbox checkbox-primary border-black"
|
class="checkbox checkbox-primary border-black"
|
||||||
on:change={updateCatchRecord}
|
on:change={onNeedsToEvolveChange}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -104,6 +104,14 @@
|
|||||||
async function updateACatch(event: any) {
|
async function updateACatch(event: any) {
|
||||||
if (!pokedexId) return;
|
if (!pokedexId) return;
|
||||||
const { catchRecord } = event.detail;
|
const { catchRecord } = event.detail;
|
||||||
|
// Enforce mutual exclusivity (should be impossible to have both true).
|
||||||
|
const sanitizedCatchRecord: CatchRecord = { ...catchRecord };
|
||||||
|
if (sanitizedCatchRecord.caught) {
|
||||||
|
sanitizedCatchRecord.haveToEvolve = false;
|
||||||
|
}
|
||||||
|
if (sanitizedCatchRecord.haveToEvolve) {
|
||||||
|
sanitizedCatchRecord.caught = false;
|
||||||
|
}
|
||||||
if (!localUser?.id) {
|
if (!localUser?.id) {
|
||||||
alert('User not signed in');
|
alert('User not signed in');
|
||||||
return;
|
return;
|
||||||
@@ -114,7 +122,7 @@
|
|||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify(catchRecord),
|
body: JSON.stringify(sanitizedCatchRecord),
|
||||||
credentials: 'include' as RequestCredentials
|
credentials: 'include' as RequestCredentials
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user