Compare commits

..

No commits in common. "daee67d6c34f023425ceb1ef669cec34b17a3027" and "82ba28adebe457a55516acc6696c87425f0dbefe" have entirely different histories.

4 changed files with 15 additions and 70 deletions

View File

@ -12,15 +12,15 @@ import (
func CreateCard(c *fiber.Ctx) error { func CreateCard(c *fiber.Ctx) error {
card := types.Card{} card := types.Card{}
if err := c.BodyParser(&card); err != nil { if err := c.BodyParser(&card); err != nil {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"status": "error", "error": "Cannot parse request", "trace": fmt.Sprint(err)}) return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Cannot parse request"})
} }
id, err := db.CreateCard(card) id, err := db.CreateCard(card)
if err != nil { if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"status": "error", "error": "Cannot create card", "trace": fmt.Sprint(err)}) return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Cannot create card", "trace": fmt.Sprint(err)})
} }
return c.Status(fiber.StatusCreated).JSON(fiber.Map{"status": "ok", "id": id}) return c.Status(fiber.StatusCreated).JSON(fiber.Map{"id": id})
} }
func GetAllCardsOf(c *fiber.Ctx) error { func GetAllCardsOf(c *fiber.Ctx) error {
@ -57,12 +57,12 @@ func GetCard(c *fiber.Ctx) error {
func DeleteCard(c *fiber.Ctx) error { func DeleteCard(c *fiber.Ctx) error {
id, err := strconv.Atoi(c.Params("id")) id, err := strconv.Atoi(c.Params("id"))
if err != nil { if err != nil {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"status": "error", "error": "Invalid card ID", "trace": fmt.Sprint(err)}) return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid card ID"})
} }
err = db.DeleteCard(id) err = db.DeleteCard(id)
if err != nil { if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"status": "error", "error": "Cannot delete card", "trace": fmt.Sprint(err)}) return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "Cannot delete card"})
} }
return c.SendStatus(fiber.StatusNoContent) return c.SendStatus(fiber.StatusNoContent)

View File

@ -12,8 +12,7 @@
tags: [] tags: []
}; };
export let showModal = false; let showModal = false;
export let onDelete: () => void;
function editCard() { function editCard() {
showModal = true; showModal = true;
@ -50,4 +49,4 @@
{/if} {/if}
</div> </div>
<ModalCard bind:show={showModal} bind:card onCancel={cancelEdit} {onDelete} /> <ModalCard bind:show={showModal} {card} onCancel={cancelEdit} />

View File

@ -7,7 +7,6 @@
export let show: boolean; export let show: boolean;
export let card: Card; export let card: Card;
export let onCancel: () => void; export let onCancel: () => void;
export let onDelete: () => void;
let tempCard: Card = { ...card }; let tempCard: Card = { ...card };
@ -19,7 +18,7 @@
content: tempCard.content content: tempCard.content
}); });
card = { ...tempCard }; card = tempCard;
} }
if (closeModal) show = false; if (closeModal) show = false;
} }
@ -33,24 +32,16 @@
<div class="header"> <div class="header">
<input class="title" bind:value={tempCard.title} on:blur={() => save(false)} /> <input class="title" bind:value={tempCard.title} on:blur={() => save(false)} />
<div class="buttons"> <div class="buttons">
<button on:click={onDelete}> <button on:click={() => save(true)}>
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
width="24" width="24"
height="24" height="24"
fill="white"
viewBox="0 0 24 24" viewBox="0 0 24 24"
fill="none"
stroke="white"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
> >
<path d="M3 6h18"></path> <path d="M0 0h24v24H0z" fill="none" />
<path <path d="M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" />
d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m2-2h10a2 2 0 0 1 2 2v2H5V6a2 2 0 0 1 2-2z"
></path>
<line x1="10" y1="11" x2="10" y2="17"></line>
<line x1="14" y1="11" x2="14" y2="17"></line>
</svg> </svg>
</button> </button>
<button on:click={onCancel}> <button on:click={onCancel}>

View File

@ -23,45 +23,6 @@
console.error(response.data); console.error(response.data);
} }
}); });
let modalID = -1;
async function newCard() {
const response = await axios.post(`${backend}/api/card`, {
project_id: projectId,
title: 'Untitled',
content: ''
});
if (response.data.status !== 'ok') {
console.error(response.data);
return;
}
const id: number = response.data.id;
let card: Card = {
id: id,
project_id: projectId,
title: 'Untitled',
content: '',
tags: []
};
cards = [...cards, card];
modalID = id;
}
async function deleteCard(cardID: number) {
const response = await axios.delete(`${backend}/api/card/${cardID}`);
if (response.status !== 204) {
console.error(response.data);
return;
}
cards = cards.filter((card) => card.id !== cardID);
}
</script> </script>
<svelte:head> <svelte:head>
@ -72,18 +33,12 @@
{#if project} {#if project}
<div id="project"> <div id="project">
<header> <h2>{project.title}</h2>
<h2>{project.title}</h2>
<button on:click={newCard}>New card</button>
</header>
<ul> <ul>
{#if cards} {#if cards}
{#each cards as card} {#each cards as card}
<CardC <CardC {card} />
{card}
showModal={modalID === card.id}
onDelete={async () => await deleteCard(card.id)}
/>
{/each} {/each}
{/if} {/if}
</ul> </ul>