Skip to content

Commit 841cdae

Browse files
committed
Await getUserFromSession and run prettier
1 parent 785f5e4 commit 841cdae

25 files changed

+99
-214
lines changed

app/actions.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@ import { cookies } from 'next/headers'
66
import { redirect } from 'next/navigation'
77
import { getUserFromSession } from '#lib/session'
88

9-
export async function saveNote(
10-
noteId: number | undefined,
11-
title: string,
12-
body: string,
13-
) {
14-
const user = getUserFromSession()
9+
export async function saveNote(noteId: number | undefined, title: string, body: string) {
10+
const user = await getUserFromSession()
1511

1612
if (!user) {
1713
redirect('/')

app/layout.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ export const metadata = {
2121
},
2222
}
2323

24-
export default async function RootLayout({
25-
children,
26-
}: {
27-
children: React.ReactNode
28-
}) {
24+
export default async function RootLayout({ children }: { children: React.ReactNode }) {
2925
return (
3026
<html>
3127
<body>
@@ -42,9 +38,7 @@ export async function Layout({ children }: { children: React.ReactNode }) {
4238
},
4339
})
4440
let notesArray = notes
45-
? (Object.values(notes) as Note[]).sort(
46-
(a, b) => Number(a.id) - Number(b.id),
47-
)
41+
? (Object.values(notes) as Note[]).sort((a, b) => Number(a.id) - Number(b.id))
4842
: []
4943

5044
return (

app/note/[id]/loading.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
export default function NoteSkeleton() {
22
return (
3-
<div
4-
className="note skeleton-container"
5-
role="progressbar"
6-
aria-busy="true"
7-
>
3+
<div className="note skeleton-container" role="progressbar" aria-busy="true">
84
<div className="note-header">
95
<div
106
className="note-title skeleton"
117
style={{ height: '3rem', width: '65%', marginInline: '12px 1em' }}
128
/>
13-
<div
14-
className="skeleton skeleton--button"
15-
style={{ width: '8em', height: '2.5em' }}
16-
/>
9+
<div className="skeleton skeleton--button" style={{ width: '8em', height: '2.5em' }} />
1710
</div>
1811
<div className="note-preview">
1912
<div className="skeleton v-stack" style={{ height: '1.5em' }} />

app/note/edit/[id]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Props = {
1313
}
1414

1515
export default async function EditPage({ params }: Props) {
16-
const user = getUserFromSession()
16+
const user = await getUserFromSession()
1717

1818
const note = await db.note.findUnique({
1919
where: {

app/note/edit/loading.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
export default function EditSkeleton() {
22
return (
3-
<div
4-
className="note-editor skeleton-container"
5-
role="progressbar"
6-
aria-busy="true"
7-
>
3+
<div className="note-editor skeleton-container" role="progressbar" aria-busy="true">
84
<div className="note-editor-form">
95
<div className="skeleton v-stack" style={{ height: '3rem' }} />
106
<div className="skeleton v-stack" style={{ height: '100%' }} />
117
</div>
128
<div className="note-editor-preview">
139
<div className="note-editor-menu">
14-
<div
15-
className="skeleton skeleton--button"
16-
style={{ width: '8em', height: '2.5em' }}
17-
/>
10+
<div className="skeleton skeleton--button" style={{ width: '8em', height: '2.5em' }} />
1811
<div
1912
className="skeleton skeleton--button"
2013
style={{ width: '8em', height: '2.5em', marginInline: '12px 0' }}

app/note/edit/page.stories.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,8 @@ export const EditNewNote: Story = {}
3939

4040
export const SaveNewNote: Story = {
4141
play: async ({ canvas, userEvent }) => {
42-
const titleInput = await canvas.findByLabelText(
43-
'Enter a title for your note',
44-
)
45-
const bodyInput = await canvas.findByLabelText(
46-
'Enter the body for your note',
47-
)
42+
const titleInput = await canvas.findByLabelText('Enter a title for your note')
43+
const bodyInput = await canvas.findByLabelText('Enter the body for your note')
4844
await userEvent.clear(titleInput)
4945
await userEvent.type(titleInput, 'New Note Title', {})
5046
await userEvent.type(bodyInput, 'New Note Body')

app/page.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
export default async function Home() {
22
return (
33
<div className="note--empty-state">
4-
<span className="note-text--empty-state">
5-
Click a note on the left to view something!
6-
</span>
4+
<span className="note-text--empty-state">Click a note on the left to view something!</span>
75
</div>
86
)
97
}

app/style.css

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ select {
106106
--outline-box-shadow-contrast: 0 0 0 2px var(--navy-blue);
107107

108108
/* Fonts */
109-
--sans-serif: -apple-system, system-ui, BlinkMacSystemFont, 'Segoe UI', Roboto,
110-
Ubuntu, Helvetica, sans-serif;
111-
--monospace: Menlo, Consolas, Monaco, Liberation Mono, Lucida Console,
112-
monospace;
109+
--sans-serif: -apple-system, system-ui, BlinkMacSystemFont, 'Segoe UI', Roboto, Ubuntu, Helvetica,
110+
sans-serif;
111+
--monospace: Menlo, Consolas, Monaco, Liberation Mono, Lucida Console, monospace;
113112
}
114113

115-
html, #storybook-root {
114+
html,
115+
#storybook-root {
116116
font-size: 100%;
117117
height: 100%;
118118
}
@@ -304,7 +304,9 @@ ul.notes-list {
304304

305305
.sidebar {
306306
background: var(--white);
307-
box-shadow: 0px 8px 24px rgba(0, 0, 0, 0.1), 0px 2px 2px rgba(0, 0, 0, 0.1);
307+
box-shadow:
308+
0px 8px 24px rgba(0, 0, 0, 0.1),
309+
0px 2px 2px rgba(0, 0, 0, 0.1);
308310
overflow-y: scroll;
309311
z-index: 1000;
310312
flex-shrink: 0;
@@ -521,7 +523,9 @@ ul.notes-list {
521523
visibility: hidden;
522524
opacity: 0;
523525
cursor: default;
524-
transition: visibility 0s linear 20ms, opacity 300ms;
526+
transition:
527+
visibility 0s linear 20ms,
528+
opacity 300ms;
525529
outline-style: none;
526530
}
527531
.sidebar-note-toggle-expand:focus {
@@ -532,15 +536,19 @@ ul.notes-list {
532536
.sidebar-note-toggle-expand:focus {
533537
visibility: visible;
534538
opacity: 1;
535-
transition: visibility 0s linear 0s, opacity 300ms;
539+
transition:
540+
visibility 0s linear 0s,
541+
opacity 300ms;
536542
}
537543

538544
@media (hover: hover) {
539545
.sidebar-note-open:hover + .sidebar-note-toggle-expand,
540546
.sidebar-note-toggle-expand:hover {
541547
visibility: visible;
542548
opacity: 1;
543-
transition: visibility 0s linear 0s, opacity 300ms;
549+
transition:
550+
visibility 0s linear 0s,
551+
opacity 300ms;
544552
}
545553
}
546554
.sidebar-note-toggle-expand img {
@@ -585,7 +593,9 @@ ul.notes-list {
585593
}
586594
.note {
587595
background: var(--white);
588-
box-shadow: 0px 4px 20px rgba(0, 0, 0, 0.1), 0px 0px 2px rgba(0, 0, 0, 0.1);
596+
box-shadow:
597+
0px 4px 20px rgba(0, 0, 0, 0.1),
598+
0px 0px 2px rgba(0, 0, 0, 0.1);
589599
border-radius: 8px;
590600
width: calc(100% - 32px);
591601
height: calc(100% - 32px);
@@ -635,7 +645,9 @@ ul.notes-list {
635645
display: flex;
636646
padding: 16px;
637647
background: var(--white);
638-
box-shadow: 0px 4px 20px rgba(0, 0, 0, 0.1), 0px 0px 2px rgba(0, 0, 0, 0.1);
648+
box-shadow:
649+
0px 4px 20px rgba(0, 0, 0, 0.1),
650+
0px 0px 2px rgba(0, 0, 0, 0.1);
639651
border-radius: 8px;
640652
width: calc(100% - 32px);
641653
height: calc(100% - 32px);

components/auth-button.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,18 @@ type Props = {
99
noteId: number | null
1010
}
1111

12-
export default function AuthButton({ children, noteId }: Props) {
13-
const user = getUserFromSession()
12+
export default async function AuthButton({ children, noteId }: Props) {
13+
const user = await getUserFromSession()
1414
const isDraft = noteId == null
1515

1616
if (user) {
1717
return (
1818
// Use hard link
1919
<Link href={`/note/edit/${noteId || ''}`} className="link--unstyled">
2020
<button
21-
className={[
22-
'edit-button',
23-
isDraft ? 'edit-button--solid' : 'edit-button--outline',
24-
].join(' ')}
21+
className={['edit-button', isDraft ? 'edit-button--solid' : 'edit-button--outline'].join(
22+
' ',
23+
)}
2524
role="menuitem"
2625
>
2726
{children}
@@ -41,10 +40,9 @@ export default function AuthButton({ children, noteId }: Props) {
4140
return (
4241
<form action={login}>
4342
<button
44-
className={[
45-
'edit-button',
46-
isDraft ? 'edit-button--solid' : 'edit-button--outline',
47-
].join(' ')}
43+
className={['edit-button', isDraft ? 'edit-button--solid' : 'edit-button--outline'].join(
44+
' ',
45+
)}
4846
role="menuitem"
4947
>
5048
Login to Add

components/logout-button.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { logout } from '#app/actions'
22
import { getUserFromSession } from '#lib/session'
33

4-
export default function LogoutButton() {
5-
const user = getUserFromSession()
4+
export default async function LogoutButton() {
5+
const user = await getUserFromSession()
66

77
return (
88
user && (
99
<form action={logout}>
10-
<button className="logout-button" type="submit" aria-label='logout'>
10+
<button className="logout-button" type="submit" aria-label="logout">
1111
<svg
1212
xmlns="http://www.w3.org/2000/svg"
1313
width="24"

components/note-editor.stories.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import { type Meta, type StoryObj } from '@storybook/react'
2-
import NoteEditor from "./note-editor";
2+
import NoteEditor from './note-editor'
33

44
const meta = {
55
component: NoteEditor,
66
args: {
77
initialTitle: 'This is a title',
88
initialBody: 'This is a body',
99
noteId: 1,
10-
}
10+
},
1111
} satisfies Meta<typeof NoteEditor>
1212

13-
export default meta;
13+
export default meta
1414

1515
type Story = StoryObj<typeof meta>
1616
export const Default: Story = {}
1717
export const Draft: Story = {
1818
args: {
1919
noteId: undefined,
20-
}
21-
}
20+
},
21+
}

components/note-editor.tsx

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ type Props = {
1212
initialBody: string
1313
}
1414

15-
export default function NoteEditor({
16-
noteId,
17-
initialTitle,
18-
initialBody,
19-
}: Props) {
15+
export default function NoteEditor({ noteId, initialTitle, initialBody }: Props) {
2016
const { pending } = useFormStatus()
2117
const [title, setTitle] = useState(initialTitle)
2218
const [body, setBody] = useState(initialBody)
@@ -39,11 +35,7 @@ export default function NoteEditor({
3935
<label className="offscreen" htmlFor="note-body-input">
4036
Enter the body for your note
4137
</label>
42-
<textarea
43-
value={body}
44-
id="note-body-input"
45-
onChange={(e) => setBody(e.target.value)}
46-
/>
38+
<textarea value={body} id="note-body-input" onChange={(e) => setBody(e.target.value)} />
4739
</form>
4840
<div className="note-editor-preview">
4941
<form className="note-editor-menu" role="menubar">
@@ -54,13 +46,7 @@ export default function NoteEditor({
5446
formAction={() => saveNote(noteId, title, body)}
5547
role="menuitem"
5648
>
57-
<Image
58-
src="/checkmark.svg"
59-
width={14}
60-
height={10}
61-
alt=""
62-
role="presentation"
63-
/>
49+
<Image src="/checkmark.svg" width={14} height={10} alt="" role="presentation" />
6450
Done
6551
</button>
6652
{!isDraft && (
@@ -70,13 +56,7 @@ export default function NoteEditor({
7056
formAction={() => deleteNote(noteId)}
7157
role="menuitem"
7258
>
73-
<Image
74-
src="/cross.svg"
75-
width={10}
76-
height={10}
77-
alt=""
78-
role="presentation"
79-
/>
59+
<Image src="/cross.svg" width={10} height={10} alt="" role="presentation" />
8060
Delete
8161
</button>
8262
)}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { type Meta, type StoryObj } from '@storybook/react'
2-
import NoteListSkeleton from "./note-list-skeleton";
2+
import NoteListSkeleton from './note-list-skeleton'
33

44
const meta = {
55
component: NoteListSkeleton,
66
} satisfies Meta<typeof NoteListSkeleton>
77

8-
export default meta;
8+
export default meta
99

1010
type Story = StoryObj<typeof meta>
11-
export const Default: Story = {}
11+
export const Default: Story = {}

components/note-list-skeleton.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,13 @@ export default function NoteListSkeleton() {
33
<div>
44
<ul className="notes-list skeleton-container">
55
<li className="v-stack">
6-
<div
7-
className="sidebar-note-list-item skeleton"
8-
style={{ height: '5em' }}
9-
/>
6+
<div className="sidebar-note-list-item skeleton" style={{ height: '5em' }} />
107
</li>
118
<li className="v-stack">
12-
<div
13-
className="sidebar-note-list-item skeleton"
14-
style={{ height: '5em' }}
15-
/>
9+
<div className="sidebar-note-list-item skeleton" style={{ height: '5em' }} />
1610
</li>
1711
<li className="v-stack">
18-
<div
19-
className="sidebar-note-list-item skeleton"
20-
style={{ height: '5em' }}
21-
/>
12+
<div className="sidebar-note-list-item skeleton" style={{ height: '5em' }} />
2213
</li>
2314
</ul>
2415
</div>

0 commit comments

Comments
 (0)