This commit is contained in:
Avraham Sakal
2025-06-27 16:25:35 -04:00
parent 2a4ff2e509
commit 602ba72f75
18 changed files with 149 additions and 67 deletions
+5 -1
View File
@@ -3,7 +3,11 @@ import { Counter } from "./Counter.js";
export default function Page() {
return (
<>
<h1 css={{ fontWeight: "700", fontSize: "1.875rem", paddingBottom: "1rem" }}>My Vike app</h1>
<h1
css={{ fontWeight: "700", fontSize: "1.875rem", paddingBottom: "1rem" }}
>
My Vike app
</h1>
This page is:
<ul>
<li>Rendered to HTML.</li>
+3 -1
View File
@@ -10,7 +10,9 @@ export const data = async (pageContext: PageContextServer) => {
// https://vike.dev/useConfig
const config = useConfig();
const response = await fetch(`https://brillout.github.io/star-wars/api/films/${pageContext.routeParams.id}.json`);
const response = await fetch(
`https://brillout.github.io/star-wars/api/films/${pageContext.routeParams.id}.json`,
);
let movie = (await response.json()) as MovieDetails;
config({
+5 -1
View File
@@ -14,7 +14,11 @@ export default function Page() {
))}
</ol>
<p>
Source: <a href="https://brillout.github.io/star-wars">brillout.github.io/star-wars</a>.
Source:{" "}
<a href="https://brillout.github.io/star-wars">
brillout.github.io/star-wars
</a>
.
</p>
</>
);
+3 -1
View File
@@ -9,7 +9,9 @@ export const data = async () => {
// https://vike.dev/useConfig
const config = useConfig();
const response = await fetch("https://brillout.github.io/star-wars/api/films.json");
const response = await fetch(
"https://brillout.github.io/star-wars/api/films.json",
);
const moviesData = (await response.json()) as MovieDetails[];
config({
+3 -1
View File
@@ -6,6 +6,8 @@ export type Data = {
todo: { text: string }[];
};
export default async function data(_pageContext: PageContextServer): Promise<Data> {
export default async function data(
_pageContext: PageContextServer,
): Promise<Data> {
return { todo: todos };
}
+11 -2
View File
@@ -1,7 +1,11 @@
import { trpc } from "../../trpc/client";
import { useState } from "react";
export function TodoList({ initialTodoItems }: { initialTodoItems: { text: string }[] }) {
export function TodoList({
initialTodoItems,
}: {
initialTodoItems: { text: string }[];
}) {
const [todoItems, setTodoItems] = useState(initialTodoItems);
const [newTodo, setNewTodo] = useState("");
return (
@@ -16,6 +20,7 @@ export function TodoList({ initialTodoItems }: { initialTodoItems: { text: strin
<form
onSubmit={async (ev) => {
ev.preventDefault();
if (newTodo.trim() === "") return;
// Optimistic UI update
setTodoItems((prev) => [...prev, { text: newTodo }]);
@@ -29,7 +34,11 @@ export function TodoList({ initialTodoItems }: { initialTodoItems: { text: strin
}
}}
>
<input type="text" onChange={(ev) => setNewTodo(ev.target.value)} value={newTodo} />
<input
type="text"
onChange={(ev) => setNewTodo(ev.target.value)}
value={newTodo}
/>
<button type="submit">Add to-do</button>
</form>
</div>