Skip to content

Commit

Permalink
add BE calls to purchase buttons in FE
Browse files Browse the repository at this point in the history
  • Loading branch information
linomp committed Feb 10, 2024
1 parent 98c2301 commit b021dd9
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions mvp/client/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,45 @@
}
};
const purchaseSensor = async (sensorName: string) => {
if (!gameSession || gameOver) {
return;
}
try {
gameSession = await PlayerActionsService.purchaseSensorPlayerActionsPurchasesSensorsPost(
sensorName,
gameSession?.id
);
} catch (error: any) {
if (error.status === 400) {
alert('Not enough funds to buy the sensor!');
} else {
console.error('Error buying sensor:', error);
}
}
};
const purchaseRulPredictionModel = async () => {
if (!gameSession || gameOver) {
return;
}
try {
gameSession =
await PlayerActionsService.purchasePredictionPlayerActionsPurchasesPredictionModelsPost(
'predicted_rul',
gameSession?.id
);
} catch (error: any) {
if (error.status === 400) {
alert('Not enough funds to buy the prediction model!');
} else {
console.error('Error buying prediction model:', error);
}
}
};
const checkForGameOver = () => {
if (!gameSession) {
return;
Expand Down Expand Up @@ -161,7 +200,10 @@
{formatParameterName(parameter)}: {value ?? '???'}
<span hidden={value != null}>
&nbsp;-&nbsp;
<button disabled={sensorPurchaseButtonDisabled}>
<button
disabled={sensorPurchaseButtonDisabled}
on:click={() => purchaseSensor(parameter)}
>
Buy (${globalSettings?.sensor_cost})
</button>
</span>
Expand All @@ -175,7 +217,10 @@
: '???'}
<span hidden={gameSession.machine_state?.predicted_rul != null}>
&nbsp;-&nbsp;
<button disabled={predictionPurchaseButtonDisabled}>
<button
disabled={predictionPurchaseButtonDisabled}
on:click={() => purchaseRulPredictionModel()}
>
Buy (${globalSettings?.prediction_model_cost})
</button>
</span>
Expand Down

0 comments on commit b021dd9

Please sign in to comment.