Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* This val creates an elegant and professional web app for managing panel members for the State Street discussion.
* It uses React for the UI, SQLite for storing panel member information, and the Fetch API to communicate with the server.
* The design is clean and sophisticated, with a muted color palette and subtle animations.
*/
/** @jsxImportSource https://esm.sh/react */
import React, { useEffect, useState } from "https://esm.sh/react";
import { createRoot } from "https://esm.sh/react-dom/client";
function App() {
const [panelMembers, setPanelMembers] = useState([]);
const [newMember, setNewMember] = useState({ name: "", expertise: "" });
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState(null);
useEffect(() => {
fetchPanelMembers();
}, []);
const fetchPanelMembers = async () => {
setIsLoading(true);
try {
const response = await fetch("/panel-members");
if (!response.ok) {
throw new Error("Failed to fetch panel members");
}
const data = await response.json();
setPanelMembers(data);
} catch (err) {
setError("Failed to load panel members. Please try again.");
} finally {
setIsLoading(false);
}
};
const addPanelMember = async (e) => {
e.preventDefault();
setIsLoading(true);
try {
const response = await fetch("/add-member", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(newMember),
});
if (!response.ok) {
throw new Error("Failed to add panel member");
}
setNewMember({ name: "", expertise: "" });
fetchPanelMembers();
} catch (err) {
setError("Failed to add panel member. Please try again.");
} finally {
setIsLoading(false);
}
};
return (
<div className="container">
<header>
<h1>State Street Discussion Panel</h1>
<p className="subtitle">Manage panel members for the upcoming discussion on urban development</p>
</header>
<section className="info-section">
<h2>About the Discussion</h2>
<p>
Join us for an insightful discussion on the future of State Street. Our panel of experts will explore urban
development strategies, community engagement, and economic revitalization.
</p>
</section>
<section className="form-section">
<h2>Add New Panel Member</h2>
<form onSubmit={addPanelMember}>
<input
type="text"
placeholder="Name"
value={newMember.name}
onChange={(e) => setNewMember({ ...newMember, name: e.target.value })}
required
/>
<input
type="text"
placeholder="Expertise"
value={newMember.expertise}
onChange={(e) => setNewMember({ ...newMember, expertise: e.target.value })}
required
/>
<button type="submit" disabled={isLoading}>
{isLoading ? "Adding..." : "Add Member"}
</button>
</form>
</section>
<section className="panel-members">
<h2>Current Panel Members</h2>
{isLoading && <p className="loading">Loading panel members...</p>}
{error && <p className="error">{error}</p>}
<ul>
cofsana-fancyplumsquirrel.web.val.run
August 22, 2024