Skip to content

Commit

Permalink
Delete history
Browse files Browse the repository at this point in the history
  • Loading branch information
prokawsar committed Jul 14, 2024
1 parent 03682d1 commit 8aed11b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/lib/elements/Input.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@

<style lang="postcss">
.input-field {
@apply border border-gray-400 w-14 p-1 rounded;
@apply border border-gray-400 w-12 p-1 rounded;
}
</style>
16 changes: 15 additions & 1 deletion src/routes/history/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
<script lang="ts">
import { invalidateAll } from '$app/navigation'
import { paperHistoryStore } from '$lib/stores'
import { deleteHistory } from '$lib/utils/services.js'
import Icon from '@iconify/svelte'
import days from 'dayjs'
export let data
$paperHistoryStore = data.histories
const handleDelete = async (id: string) => {
await deleteHistory(id)
await invalidateAll()
}
</script>

<svelte:head>
Expand All @@ -24,7 +32,7 @@
{#if data.histories.length}
{#each data.histories.reverse() as { name, id, final_price, papers, created_at }, i}
<div
class="flex flex-col gap-1 items-center w-full p-2 border border-dashed rounded shadow-sm"
class="flex flex-col gap-1 items-center w-full p-1 border border-dashed rounded shadow-sm"
>
<a href="/history/{id}" class="flex flex-row items-center pl-1 justify-between w-full">
<p class:hidden={!name} class="w-fit">
Expand All @@ -36,6 +44,12 @@
<p class="text-gray-500">
{final_price.toFixed(2)}
</p>
<button
class="border border-gray-400 rounded-md text-red-600 p-1 w-fit disabled:border-gray-200 disabled:cursor-not-allowed disabled:text-opacity-45"
on:click|stopPropagation|preventDefault={() => handleDelete(id)}
>
<Icon icon="ph:trash-light" width="16px" />
</button>
</a>
</div>
{/each}
Expand Down
20 changes: 11 additions & 9 deletions src/routes/history/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import Result from '$lib/elements/Result.svelte'
import { paperHistoryStore } from '$lib/stores'
import dayjs from 'dayjs'
import type { CostHistoryType } from '$lib/utils/services'
import { calculateCost, type CostHistoryType } from '$lib/utils/services'
const data: CostHistoryType[] = $paperHistoryStore.filter(
(history) => history.id == $page.params.id
Expand All @@ -29,18 +29,20 @@
<div class="flex flex-col overflow-y-auto w-full max-w-3xl py-2">
{#if data.length}
{#each data as history, i}
{#each history.papers as { length, width, thickness, rate }, i}
<div class="flex flex-col gap-1 items-center w-full rounded">
<div class="grid grid-cols-4 w-full gap-1 items-center overflow-x-auto p-1">
{#each history.papers as { length, width, thickness, rate, id }, i}
<div class="flex flex-col items-center w-full rounded">
<div
class="flex flex-row w-full gap-1 items-center justify-between overflow-x-auto p-1"
>
<Input bind:value={length} disabled />
<Input bind:value={width} disabled />
<Input bind:value={thickness} disabled />
<Input bind:value={rate} disabled />
<!-- <div class="flex justify-start">
<p>
= {finalPrice.toFixed(2)}
</p>
</div> -->
<div class="flex justify-center">
<p class="font-semibold">
= {calculateCost({ length, width, thickness, rate, id }).toFixed(2)}
</p>
</div>
</div>
</div>
{/each}
Expand Down

0 comments on commit 8aed11b

Please sign in to comment.