-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Possibility to delete item from checklist
Fixes #60
- Loading branch information
1 parent
fd444b9
commit b1c3fbe
Showing
20 changed files
with
201 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// overflow ellipsis | ||
@mixin overflow-ellipsis { | ||
white-space: nowrap; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,71 @@ | ||
<template> | ||
<div :class="$style.component"> | ||
<div> | ||
<div :class="$style.name"> | ||
{{ item.equipment.name}} | ||
</div> | ||
|
||
<div :class="$style.weight"> | ||
{{ item.equipment.weight }} | ||
</div> | ||
|
||
<div :class="$style.actions"> | ||
<IconButton | ||
size="xs" | ||
icon-name="tabler:x" | ||
@click="handleRemoveClick" | ||
/> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import type { ChecklistItemModel } from '~/models/checklist'; | ||
import IconButton from '@/components/IconButton.vue'; | ||
interface Props { | ||
readonly item: ChecklistItemModel; | ||
} | ||
defineProps<Props>(); | ||
const props = defineProps<Props>(); | ||
const route = useRoute(); | ||
const { removeItem } = useChecklistStore(); | ||
async function handleRemoveClick() { | ||
if (typeof route.params.checklistId === 'string' && typeof props.item.id === 'string') { | ||
await removeItem(route.params.checklistId, props.item.id); | ||
} | ||
} | ||
</script> | ||
|
||
<style module> | ||
<style lang="scss" module> | ||
.component { | ||
height: 40px; | ||
display: grid; | ||
grid-template-columns: 1fr auto; | ||
padding: var(--border-radius-8) var(--spacing-12); | ||
grid-template-columns: minmax(100px, 30%) auto auto; | ||
align-items: center; | ||
padding: 0 var(--spacing-12); | ||
background-color: var(--color-blue-100); | ||
border: 1px solid var(--color-blue-300); | ||
border-radius: var(--border-radius-12); | ||
font-size: var(--font-size-16); | ||
color: var(--color-blue-800); | ||
} | ||
.name { | ||
@include overflow-ellipsis(); | ||
} | ||
.weight { | ||
color: var(--color-blue-700); | ||
font-size: var(--font-size-14); | ||
} | ||
.actions { | ||
justify-self: end; | ||
} | ||
.icon { | ||
display: block; | ||
cursor: pointer; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
import type { ChecklistItemModel } from "~/models/checklist" | ||
|
||
export async function useChecklistItemsData(checklistId: string) { | ||
const items = ref<ChecklistItemModel[]>([]) | ||
const { items } = useChecklistStore() | ||
const { data } = await useFetch(`/api/checklists/${checklistId}/items`) | ||
|
||
if (data.value !== undefined) { | ||
items.value = data.value | ||
} | ||
|
||
return items | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import type { ChecklistItemModel } from "~/models/checklist"; | ||
|
||
export function useChecklistStore() { | ||
const items = useState<ChecklistItemModel[]>('checklistItems', () => []) | ||
|
||
async function removeItem(checklistId: string, itemId: string) { | ||
try { | ||
const deletedItem = await $fetch(`/api/checklists/${checklistId}/items/${itemId}`, { | ||
method: 'DELETE' | ||
}); | ||
|
||
items.value = items.value.filter(item => item.id !== deletedItem.id); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} | ||
|
||
async function addItem(checklistId: string, equipmentId: string) { | ||
try { | ||
const insertedItem = await $fetch(`/api/checklists/${checklistId}/items`, { | ||
method: 'POST', | ||
|
||
body: { | ||
equipmentId | ||
} | ||
}); | ||
|
||
if (insertedItem !== undefined) { | ||
items.value.push({ | ||
id: insertedItem.id, | ||
equipment: insertedItem.equipment | ||
}) | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} | ||
|
||
return { | ||
items, | ||
removeItem, | ||
addItem | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.