-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from tawaks/feature/add-hobbies
[Feature] Add Hobbies (#55)
- Loading branch information
Showing
12 changed files
with
220 additions
and
4 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
prisma/migrations/20241022160425_add_hobbies/migration.sql
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,15 @@ | ||
-- AlterTable | ||
ALTER TABLE "User" ADD COLUMN "openToCollaborating" BOOLEAN NOT NULL DEFAULT false; | ||
|
||
-- CreateTable | ||
CREATE TABLE "Hobby" ( | ||
"id" SERIAL NOT NULL, | ||
"userId" INTEGER NOT NULL, | ||
"hobby" TEXT NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
||
CONSTRAINT "Hobby_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "Hobby" ADD CONSTRAINT "Hobby_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("githubId") ON DELETE RESTRICT ON UPDATE CASCADE; |
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,3 @@ | ||
# Please do not edit this file manually | ||
# It should be added in your version-control system (i.e. Git) | ||
provider = "postgresql" |
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,33 @@ | ||
<script lang="ts"> | ||
import * as Form from '$lib/components/ui/form'; | ||
import { Input } from '$lib/components/ui/input'; | ||
import { hobbiesSchema, type HobbiesSchema } from '$lib/schemas/hobbies'; | ||
import { type SuperValidated, type Infer, superForm } from 'sveltekit-superforms'; | ||
import { zodClient } from 'sveltekit-superforms/adapters'; | ||
export let data: SuperValidated<Infer<HobbiesSchema>>; | ||
const form = superForm(data, { | ||
validators: zodClient(hobbiesSchema), | ||
resetForm: true, | ||
}); | ||
const { form: formData, enhance } = form; | ||
</script> | ||
|
||
<form | ||
method="POST" | ||
use:enhance | ||
action="?/createHobby" | ||
class="flex items-center justify-between space-x-4"> | ||
<div class="flex items-end space-x-2"> | ||
<Form.Field {form} name="hobby"> | ||
<Form.Control let:attrs> | ||
<Form.Label>Hobby</Form.Label> | ||
<Input {...attrs} bind:value={$formData.hobby} /> | ||
</Form.Control> | ||
</Form.Field> | ||
<Form.Button>Add</Form.Button> | ||
</div> | ||
</form> |
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,28 @@ | ||
<script lang="ts"> | ||
import { Heart,Trash2 } from 'lucide-svelte'; | ||
import { Button } from '$lib/components/ui/button'; | ||
import { enhance } from '$app/forms'; | ||
import { confirmDelete } from '$lib/utils/confirmDelete'; | ||
import type { Hobby } from '@prisma/client'; | ||
export let hobbies: Hobby[]; | ||
</script> | ||
|
||
<div class="grid gap-4"> | ||
{#each hobbies as hobby} | ||
<div class="flex items-center gap-4"> | ||
<Heart /> | ||
<div class="grid gap-1"> | ||
<p class="text-sm font-medium leading-none">{hobby.hobby}</p> | ||
</div> | ||
<div class="ml-auto font-medium"> | ||
<form action="?/deleteHobby&id={hobby.id}" method="POST" use:enhance> | ||
<Button type="submit" variant="ghost" on:click={confirmDelete}> | ||
<Trash2 /> | ||
</Button> | ||
</form> | ||
</div> | ||
</div> | ||
{/each} | ||
</div> |
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,35 @@ | ||
<script lang="ts"> | ||
import * as Table from '$lib/components/ui/table'; | ||
import * as Card from '$lib/components/ui/card'; | ||
import type { PublicProfile } from '$lib/types/PublicProfile'; | ||
export let userData: PublicProfile; | ||
</script> | ||
|
||
<Card.Root> | ||
<Card.Header> | ||
<Card.Title>Hobbies</Card.Title> | ||
<Card.Description>Discover the developer's hobbies</Card.Description> | ||
</Card.Header> | ||
<Card.Content class="grid gap-4"> | ||
{#if userData.hobbies.length > 0} | ||
<Table.Root> | ||
<Table.Header> | ||
<Table.Row> | ||
<Table.Head>Hobby</Table.Head> | ||
</Table.Row> | ||
</Table.Header> | ||
<Table.Body> | ||
{#each userData.hobbies as hobby} | ||
<Table.Row class="flex flex-row space-x-4 hover:cursor-pointer"> | ||
<Table.Cell class="font-medium">{hobby.hobby}</Table.Cell> | ||
</Table.Row> | ||
{/each} | ||
</Table.Body> | ||
</Table.Root> | ||
{:else} | ||
<p class="text-muted-foreground">No hobbies available</p> | ||
{/if} | ||
</Card.Content> | ||
</Card.Root> | ||
|
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,7 @@ | ||
import { z } from 'zod'; | ||
|
||
export const hobbiesSchema = z.object({ | ||
hobby: z.string().min(1).max(100), | ||
}); | ||
|
||
export type HobbiesSchema = typeof hobbiesSchema; |
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