Migrate jobView components

This commit is contained in:
Christoph Kluge
2025-06-20 18:14:36 +02:00
parent d731611e0c
commit d7379a1af2
3 changed files with 113 additions and 87 deletions

View File

@@ -9,7 +9,8 @@
<script>
import {
getContext
getContext,
onMount
} from "svelte";
import {
Card,
@@ -21,17 +22,26 @@
} from "@sveltestrap/sveltestrap";
import { round } from "mathjs";
export let jobId;
export let jobEnergy = null;
export let jobEnergyFootprint = null;
/* Svelte 5 Props */
let {
jobId,
jobEnergy = null,
jobEnergyFootprint = null
} = $props();
/* Const Init */
const carbonPerkWh = getContext("emission");
let carbonMass;
/* State Init */
let carbonMass = $state(0);
$: if (carbonPerkWh) {
// ( kWh * g/kWh) / 1000 = kg || Rounded to 2 Digits via [ round(x * 100) / 100 ]
carbonMass = round( ((jobEnergy ? jobEnergy : 0.0) * carbonPerkWh) / 10 ) / 100;
}
/* On Mount */
onMount(() => {
if (carbonPerkWh) {
// ( kWh * g/kWh) / 1000 = kg || Rounded to 2 Digits via [ round(x * 100) / 100 ]
carbonMass = round( ((jobEnergy ? jobEnergy : 0.0) * carbonPerkWh) / 10 ) / 100;
}
});
</script>
<Card>