Skip to content

Commit f53a78b

Browse files
committed
update: formatting changes
1 parent be96203 commit f53a78b

4 files changed

Lines changed: 121 additions & 29 deletions

File tree

app/api/items/route.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
import { NextResponse } from 'next/server';
1+
import { NextResponse } from "next/server";
22
let items = [
3-
{ id: 1, title: 'Alpha', description: 'First item (server)' },
4-
{ id: 2, title: 'Bravo', description: 'Second item (server)' },
5-
{ id: 3, title: 'Charlie', description: 'Third item (server)' }
3+
{ id: 1, title: "Alpha", description: "First item (server)" },
4+
{ id: 2, title: "Bravo", description: "Second item (server)" },
5+
{ id: 3, title: "Charlie", description: "Third item (server)" },
66
];
7-
export async function GET() { return NextResponse.json(items); }
7+
export async function GET() {
8+
return NextResponse.json(items);
9+
}
810
export async function POST(req: Request) {
911
const body = await req.json();
10-
const id = Math.max(...items.map(i => i.id)) + 1;
11-
const created = { id, title: body.title ?? 'Untitled', description: body.description ?? '' };
12+
const id = Math.max(...items.map((i) => i.id)) + 1;
13+
const created = {
14+
id,
15+
title: body.title ?? "Untitled",
16+
description: body.description ?? "",
17+
};
1218
items = [...items, created];
1319
return NextResponse.json(created, { status: 201 });
1420
}

app/globals.css

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,59 @@
1-
*{box-sizing:border-box}body{font-family:ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial,'Apple Color Emoji','Segoe UI Emoji'}
2-
a{color:#2563eb;text-decoration:none}ul{padding-left:1rem}li{margin:.25rem 0}.card{border:1px solid #e5e7eb;border-radius:8px;padding:12px}
3-
.grid{display:grid;grid-template-columns:280px 1fr;gap:16px}.input{padding:8px;border:1px solid #e5e7eb;border-radius:6px;width:100%}
4-
.btn{padding:8px 12px;border-radius:6px;background:#2563eb;color:#fff;border:none;cursor:pointer}.btn:disabled{opacity:.5;cursor:not-allowed}
5-
.list-item{padding:8px;border-radius:6px;border:1px solid #e5e7eb;cursor:pointer}.list-item--active{background:#eff6ff;border-color:#93c5fd}.small{color:#6b7280;font-size:.875rem}
1+
* {
2+
box-sizing: border-box;
3+
}
4+
body {
5+
font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto,
6+
Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
7+
}
8+
a {
9+
color: #2563eb;
10+
text-decoration: none;
11+
}
12+
ul {
13+
padding-left: 1rem;
14+
}
15+
li {
16+
margin: 0.25rem 0;
17+
}
18+
.card {
19+
border: 1px solid #e5e7eb;
20+
border-radius: 8px;
21+
padding: 12px;
22+
}
23+
.grid {
24+
display: grid;
25+
grid-template-columns: 280px 1fr;
26+
gap: 16px;
27+
}
28+
.input {
29+
padding: 8px;
30+
border: 1px solid #e5e7eb;
31+
border-radius: 6px;
32+
width: 100%;
33+
}
34+
.btn {
35+
padding: 8px 12px;
36+
border-radius: 6px;
37+
background: #2563eb;
38+
color: #fff;
39+
border: none;
40+
cursor: pointer;
41+
}
42+
.btn:disabled {
43+
opacity: 0.5;
44+
cursor: not-allowed;
45+
}
46+
.list-item {
47+
padding: 8px;
48+
border-radius: 6px;
49+
border: 1px solid #e5e7eb;
50+
cursor: pointer;
51+
}
52+
.list-item--active {
53+
background: #eff6ff;
54+
border-color: #93c5fd;
55+
}
56+
.small {
57+
color: #6b7280;
58+
font-size: 0.875rem;
59+
}

app/layout.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1-
import type { ReactNode } from 'react';
2-
import './globals.css';
3-
export const metadata = { title: 'React MDV 30 Challenges (Full)', description: 'Master–Detail learning path' };
1+
import type { ReactNode } from "react";
2+
import "./globals.css";
3+
export const metadata = {
4+
title: "React Fundamental Cycle",
5+
description: "Learn React by building a master-detail app",
6+
};
47
export default function RootLayout({ children }: { children: ReactNode }) {
5-
return (<html lang="en"><body><main style={{ maxWidth: 980, margin: '0 auto', padding: 16 }}>{children}</main></body></html>);
8+
return (
9+
<html lang="en">
10+
<body>
11+
<main style={{ maxWidth: 980, margin: "0 auto", padding: 16 }}>
12+
{children}
13+
</main>
14+
</body>
15+
</html>
16+
);
617
}

app/page.tsx

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,47 @@
1-
'use client';
2-
import { useState } from 'react';
1+
"use client";
2+
import { useState } from "react";
33
const items = [
4-
{ id: 1, title: 'Alpha', description: 'First item' },
5-
{ id: 2, title: 'Bravo', description: 'Second item' },
6-
{ id: 3, title: 'Charlie', description: 'Third item' }
4+
{ id: 1, title: "Alpha", description: "First item" },
5+
{ id: 2, title: "Bravo", description: "Second item" },
6+
{ id: 3, title: "Charlie", description: "Third item" },
77
];
88
export default function Home() {
9-
const [activeId, setActiveId] = useState<number|undefined>(1);
10-
const active = items.find(i => i.id === activeId);
9+
const [activeId, setActiveId] = useState<number | undefined>(1);
10+
const active = items.find((i) => i.id === activeId);
1111
return (
1212
<section>
13-
<h1>Container–Presenter (Base)</h1>
13+
<h1>Master Detail</h1>
1414
<div className="grid" style={{ marginTop: 12 }}>
1515
<aside>
16-
<div className="card"><h3>Items</h3>
17-
<div>{items.map(it => (
18-
<div key={it.id} className={`list-item ${it.id===activeId?'list-item--active':''}`} onClick={() => setActiveId(it.id)}>{it.title}</div>
19-
))}</div>
16+
<div className="card">
17+
<h3>Items</h3>
18+
<div>
19+
{items.map((it) => (
20+
<div
21+
key={it.id}
22+
className={`list-item ${
23+
it.id === activeId ? "list-item--active" : ""
24+
}`}
25+
onClick={() => setActiveId(it.id)}
26+
>
27+
{it.title}
28+
</div>
29+
))}
30+
</div>
2031
</div>
2132
</aside>
2233
<article>
23-
<div className="card"><h3>Detail</h3>{active ? (<><h2>{active.title}</h2><p className="small">{active.description}</p></>) : 'Choose one'}</div>
34+
<div className="card">
35+
<h3>Detail</h3>
36+
{active ? (
37+
<>
38+
<h2>{active.title}</h2>
39+
<p className="small">{active.description}</p>
40+
</>
41+
) : (
42+
"Choose one"
43+
)}
44+
</div>
2445
</article>
2546
</div>
2647
</section>

0 commit comments

Comments
 (0)