Skip to content

Commit 5af4bba

Browse files
Merge pull request #13 from MichaelHolley/develop
Develop into main
2 parents 453b527 + 907d9af commit 5af4bba

File tree

9 files changed

+58
-36
lines changed

9 files changed

+58
-36
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
44
# HabitKit
55

6-
[![Build & Publish](https://github.com/MichaelHolley/HabitKit/actions/workflows/nixpacks_publish.yml/badge.svg?branch=main)](https://github.com/MichaelHolley/HabitKit/actions/workflows/nixpacks_publish.yml)
7-
86
A simple and intuitive app to track, build, and maintain your habits for a better you!
97

10-
![image](https://github.com/user-attachments/assets/1fcd0733-f82f-474f-a1b5-844f9167aae8)
8+
![image](https://github.com/user-attachments/assets/aa915619-9d38-40d7-bbe8-a5d9110f86f6)
119

1210
## Running locally
1311

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE `Habit` ADD COLUMN `description` VARCHAR(255) NULL;

prisma/schema.prisma

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ model Session {
3030
}
3131

3232
model Habit {
33-
id String @id @default(uuid())
34-
name String
35-
userId String
36-
createdAt DateTime @default(now())
37-
updatedAt DateTime @updatedAt
38-
dates Json
33+
id String @id @default(uuid())
34+
name String
35+
description String? @db.VarChar(255)
36+
userId String
37+
createdAt DateTime @default(now())
38+
updatedAt DateTime @updatedAt
39+
dates Json
3940
4041
user User @relation(fields: [userId], references: [id])
4142
}

src/lib/server/habit.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ export const updateDates = async (id: string, userId: string, dates: string[]) =
3535
});
3636
};
3737

38-
export const createHabit = async (name: string, userId: string) => {
38+
export const createHabit = async (name: string, userId: string, description?: string) => {
3939
return await prisma.habit.create({
4040
data: {
41-
name: name as string,
41+
name: name,
42+
description: description,
4243
userId: userId,
4344
dates: []
4445
}

src/routes/(app)/+page.svelte

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
<a href="/create" class="btn btn-outline btn-primary btn-sm">+ Track New</a>
1313
</div>
1414

15-
<div class="my-6">
16-
<h3 class="mb-2 text-xl">Last 30 Days</h3>
17-
<LastXDays summary={data.summary} />
18-
</div>
15+
{#if data.summary.length > 0}
16+
<div class="my-6">
17+
<h3 class="mb-2 text-xl">Last 30 Days</h3>
18+
<LastXDays summary={data.summary} />
19+
</div>
20+
{/if}
1921

2022
<div class="my-6">
2123
<div class="flex flex-row flex-wrap justify-start gap-6">

src/routes/(app)/[id]/+page.svelte

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { enhance } from '$app/forms';
33
import HabitActivityHistory from '$lib/components/Habit/HabitActivityHistory.svelte';
44
import NavigateBackButton from '$lib/components/NavigateBackButton.svelte';
5+
import dayjs from 'dayjs';
56
import type { PageData } from './$types';
67
78
let { data }: { data: PageData } = $props();
@@ -12,15 +13,18 @@
1213
<NavigateBackButton backUrl="/" />
1314
</div>
1415

15-
<h2 class="mb-3 text-3xl">{data.habit?.name}</h2>
16-
<div class="grid gap-x-3 text-start text-xs">
17-
<p class="text-neutral-400">Created:</p>
18-
<p class="text-neutral-400">
19-
{data.habit?.createdAt.toLocaleString('de', { dateStyle: 'medium', timeStyle: 'short' })}
16+
<div class="mb-3">
17+
<h2 class="text-3xl">{data.habit?.name}</h2>
18+
<p class="text-xs text-neutral-400">{data.habit?.description}</p>
19+
</div>
20+
<div class="grid gap-x-3 text-xs text-neutral-400">
21+
<p>Created:</p>
22+
<p>
23+
{dayjs(data.habit?.createdAt).format('DD MMM YYYY - HH:mm')}
2024
</p>
21-
<p class="text-neutral-400">Updated:</p>
22-
<p class="text-neutral-400">
23-
{data.habit?.updatedAt.toLocaleString('de', { dateStyle: 'medium', timeStyle: 'short' })}
25+
<p>Updated:</p>
26+
<p>
27+
{dayjs(data.habit?.updatedAt).format('DD MMM YYYY - HH:mm')}
2428
</p>
2529
</div>
2630

@@ -40,8 +44,10 @@
4044
use:enhance
4145
class="flex max-w-md grow flex-col items-end gap-3"
4246
>
43-
<label class="flex w-full flex-col gap-1 text-sm">
44-
Date
47+
<label class="form-control w-full text-sm">
48+
<div class="label">
49+
<span class="label-text">Date</span>
50+
</div>
4551
<input name="date" type="date" class="input input-bordered" required />
4652
</label>
4753

src/routes/(app)/create/+page.server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ export const actions: Actions = {
66
createHabit: async (event) => {
77
const formData = await event.request.formData();
88
const name = formData.get('name');
9+
const description = formData.get('description');
910

1011
if (!event.locals.user) {
1112
return redirect(302, '/');
1213
}
1314

14-
const habit = await createHabit(name as string, event.locals.user.id);
15+
const habit = await createHabit(name as string, event.locals.user.id, description as string);
1516

1617
return redirect(302, `/${habit.id}`);
1718
}

src/routes/(app)/create/+page.svelte

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@
55
<div class="max-w-md">
66
<h3 class="pb-4 text-3xl">Create Habit</h3>
77
<form method="POST" action="?/createHabit" use:enhance class="flex flex-col items-end gap-3">
8-
<label class="flex w-full flex-col gap-1 text-sm">
9-
Name
10-
<input name="name" class="input input-bordered" />
8+
<label class="form-control w-full text-sm">
9+
<div class="label">
10+
<span class="label-text">Name</span>
11+
</div>
12+
<input name="name" class="input input-bordered" required />
13+
</label>
14+
<label class="form-control w-full text-sm">
15+
<div class="label">
16+
<span class="label-text">Description (optional)</span>
17+
</div>
18+
<input name="description" class="input input-bordered" />
1119
</label>
12-
1320
<button class="btn btn-primary w-fit">+ Create</button>
1421
</form>
1522
</div>

src/routes/auth/+page.svelte

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111
<p>Keep track of your habits and goals</p>
1212
</div>
1313
<form method="POST" action="?/login" use:enhance class="flex flex-col gap-3">
14-
<label class="flex flex-col gap-1 text-sm">
15-
Username
16-
<input name="username" class="input input-bordered" />
14+
<label class="form-control w-full text-sm">
15+
<div class="label">
16+
<span class="label-text">Username</span>
17+
</div>
18+
<input name="username" class="input input-bordered" required />
1719
</label>
18-
<label class="flex flex-col gap-1 text-sm">
19-
Password
20-
<input type="password" name="password" class="input input-bordered" />
20+
<label class="form-control w-full text-sm">
21+
<div class="label">
22+
<span class="label-text">Password</span>
23+
</div>
24+
<input type="password" name="password" class="input input-bordered" required />
2125
</label>
2226
<button class="btn btn-primary">Login</button>
2327
<button class="btn btn-outline btn-primary" formaction="?/register">Register</button>

0 commit comments

Comments
 (0)