Skip to content

Commit a7dbf40

Browse files
committed
04/03: add location database field, render in ui
1 parent d8d5ef0 commit a7dbf40

File tree

11 files changed

+46
-7
lines changed

11 files changed

+46
-7
lines changed

exercises/03.guides/04.problem.api-mocking/app/routes/users+/$username_+/__note-editor.server.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export async function action({ request }: ActionFunctionArgs) {
9393
id: noteId,
9494
title,
9595
content,
96+
location,
9697
imageUpdates = [],
9798
newImages = [],
9899
} = submission.value
@@ -105,11 +106,13 @@ export async function action({ request }: ActionFunctionArgs) {
105106
ownerId: userId,
106107
title,
107108
content,
109+
location,
108110
images: { create: newImages },
109111
},
110112
update: {
111113
title,
112114
content,
115+
location,
113116
images: {
114117
deleteMany: { id: { notIn: imageUpdates.map((i) => i.id) } },
115118
updateMany: imageUpdates.map((updates) => ({

exercises/03.guides/04.problem.api-mocking/app/routes/users+/$username_+/notes.$noteId.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export async function loader({ params }: Route.LoaderArgs) {
2828
id: true,
2929
title: true,
3030
content: true,
31+
location: true,
3132
ownerId: true,
3233
updatedAt: true,
3334
images: {
@@ -120,6 +121,17 @@ export default function NoteRoute({
120121
<h2 id="note-title" className="text-h2 mb-2 pt-12 lg:mb-6">
121122
{loaderData.note.title}
122123
</h2>
124+
{loaderData.note.location ? (
125+
<Icon name="globe" className="text-foreground/60">
126+
<p
127+
role="note"
128+
aria-label="Location"
129+
className="text-foreground/60 text-sm font-medium"
130+
>
131+
{loaderData.note.location}
132+
</p>
133+
</Icon>
134+
) : null}
123135
<div className={`${displayBar ? 'pb-24' : 'pb-12'} overflow-y-auto`}>
124136
<ul className="flex flex-wrap gap-5 py-5">
125137
{loaderData.note.images.map((image) => (
Lines changed: 1 addition & 0 deletions
Loading

exercises/03.guides/04.problem.api-mocking/prisma/schema.prisma

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ model User {
3030
}
3131

3232
model Note {
33-
id String @id @default(cuid())
34-
title String
35-
content String
33+
id String @id @default(cuid())
34+
title String
35+
content String
36+
location String?
3637
3738
createdAt DateTime @default(now())
3839
updatedAt DateTime @updatedAt

exercises/03.guides/04.solution.api-mocking/app/routes/users+/$username_+/__note-editor.server.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export async function action({ request }: ActionFunctionArgs) {
9393
id: noteId,
9494
title,
9595
content,
96+
location,
9697
imageUpdates = [],
9798
newImages = [],
9899
} = submission.value
@@ -105,11 +106,13 @@ export async function action({ request }: ActionFunctionArgs) {
105106
ownerId: userId,
106107
title,
107108
content,
109+
location,
108110
images: { create: newImages },
109111
},
110112
update: {
111113
title,
112114
content,
115+
location,
113116
images: {
114117
deleteMany: { id: { notIn: imageUpdates.map((i) => i.id) } },
115118
updateMany: imageUpdates.map((updates) => ({

exercises/03.guides/04.solution.api-mocking/app/routes/users+/$username_+/notes.$noteId.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export async function loader({ params }: Route.LoaderArgs) {
2828
id: true,
2929
title: true,
3030
content: true,
31+
location: true,
3132
ownerId: true,
3233
updatedAt: true,
3334
images: {
@@ -120,6 +121,17 @@ export default function NoteRoute({
120121
<h2 id="note-title" className="text-h2 mb-2 pt-12 lg:mb-6">
121122
{loaderData.note.title}
122123
</h2>
124+
{loaderData.note.location ? (
125+
<Icon name="globe" className="text-foreground/60">
126+
<p
127+
role="note"
128+
aria-label="Location"
129+
className="text-foreground/60 text-sm font-medium"
130+
>
131+
{loaderData.note.location}
132+
</p>
133+
</Icon>
134+
) : null}
123135
<div className={`${displayBar ? 'pb-24' : 'pb-12'} overflow-y-auto`}>
124136
<ul className="flex flex-wrap gap-5 py-5">
125137
{loaderData.note.images.map((image) => (
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "Note" ADD COLUMN "location" TEXT;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Please do not edit this file manually
22
# It should be added in your version-control system (e.g., Git)
3-
provider = "sqlite"
3+
provider = "sqlite"

exercises/03.guides/04.solution.api-mocking/prisma/schema.prisma

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ model User {
3030
}
3131

3232
model Note {
33-
id String @id @default(cuid())
34-
title String
35-
content String
33+
id String @id @default(cuid())
34+
title String
35+
content String
36+
location String?
3637
3738
createdAt DateTime @default(now())
3839
updatedAt DateTime @updatedAt

0 commit comments

Comments
 (0)