26});
2728export function App() {
29const [audio, setAudio] = useLocalStorage("AUDIO", false);
30const user = useUser();
1415// Create the attendees table if it doesn't exist
16async function initializeDatabase() {
17console.log("Initializing database...");
18try {
Townie-02useUser.tsx1 match
3const USER_ENDPOINT = "/api/user";
45export function useUser () {
6const [data, setData] = useState<any>(null);
7const [loading, setLoading] = useState(true);
Townie-02system_prompt.txt12 matches
45- Ask clarifying questions when requirements are ambiguous
6- Provide complete, functional solutions rather than skeleton implementations
7- Test your logic against edge cases before presenting the final solution
8- Ensure all code follows Val Town's specific platform requirements
17- **Never bake in secrets into the code** - always use environment variables
18- Include comments explaining complex logic (avoid commenting obvious operations)
19- Follow modern ES6+ conventions and functional programming practices if possible
2021## Types of triggers
2829```ts
30export default async function (req: Request) {
31return new Response("Hello World");
32}
4041```ts
42export default async function () {
43// Scheduled task code
44}
5253```ts
54export default async function (email: Email) {
55// Process email
56}
60## Val Town Standard Libraries
6162Val Town provides several hosted services and utility functions.
6364### Blob Storage
114```
115116## Val Town Utility Functions
117118Val Town provides several utility functions to help with common project tasks.
119120### Importing Utilities
194โ โโโ database/
195โ โ โโโ migrations.ts # Schema definitions
196โ โ โโโ queries.ts # DB query functions
197โ โ โโโ README.md
198โ โโโ routes/ # Route modules
213โโโ shared/
214โโโ README.md
215โโโ utils.ts # Shared types and functions
216```
217221- Main entry point should be `backend/index.ts`
222- Do NOT use Hono serveStatic middleware
223- **Static asset serving:** Use the utility functions to read and serve project files:
224```ts
225import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
255- Run migrations on startup or comment out for performance
256- Change table names when modifying schemas rather than altering
257- Export clear query functions with proper TypeScript typing
258259## Common Gotchas and Solutions
Townie-02useBranches.tsx1 match
3const ENDPOINT = "/api/project-branches";
45export function useBranches (projectId: string) {
6const [data, setData] = useState<any>(null);
7const [loading, setLoading] = useState(true);
Townie-02useProject.tsx1 match
4const FILES_ENDPOINT = "/api/project-files";
56export function useProject (projectId: string, branchId?: string) {
7const [data, setData] = useState<any>(null);
8const [loading, setLoading] = useState(true);
Townie-02BranchSelect.tsx1 match
7const NEW_BRANCH_VAL = "__NEW_BRANCH__";
89export function BranchSelect () {
10const { projectId, branchId } = useParams() as {
11projectId: string;
Townie-02useProjects.tsx1 match
3const ENDPOINT = "/api/projects-loader";
45export function useProjects () {
6const [data, setData] = useState<any>(null);
7const [loading, setLoading] = useState(true);
Townie-02Header.tsx5 matches
6import { AppContext } from "./App.tsx";
78export function Header () {
9const navigate = useNavigate();
1025}
2627function LogOut () {
28const { user } = useContext(AppContext);
29return (
46}
4748function ValTownLogo () {
49return (
50<svg
64}
6566function DarkButton () {
67const [dark, setDark] = useLocalStorage("DARK_MODE", false);
68const toggle = () => {
89}
9091function AudioButton () {
92const {audio, setAudio} = useContext(AppContext);
93
town-hallEventDetails.tsx1 match
2import React from "https://esm.sh/react@18.2.0?deps=react@18.2.0";
34export function EventDetails() {
5return (
6<div className="mt-4 p-4 bg-blue-50 rounded-lg border border-blue-100 text-gray-700 text-left w-full">