18});
1920export function App() {
21const [audio, setAudio] = useLocalStorage("AUDIO", false);
22const user = useUser();
TownieuseUser.tsx1 match
3const USER_ENDPOINT = "/api/user";
45export function useUser() {
6const [data, setData] = useState<any>(null);
7const [loading, setLoading] = useState(true);
TownieInlinePreview.tsx2 matches
4import { MessageContext } from "./Messages.tsx";
56export function InlinePreview ({ part }) {
7const project = useContext(ProjectContext);
8const message = useContext(MessageContext);
73const SCREENSHOT_URL = "https://screenshots.valtown.net/screenshot.png";
7475function getScreenshotURL ({
76version,
77endpoint,
TownieChatRouteSingleColumn.tsx3 matches
1920// alt single-column version of /chat route
21export function ChatRouteSingleColumn () {
22const { projectId, branchId } = useParams() as {
23projectId: string;
56}
5758function Conversation ({
59project,
60files,
177}
178179function shouldRefetch (message) {
180for (let i = 0; i < message?.parts?.length; i++) {
181let part = message.parts[i];
Townie.cursorrules12 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}
4243```ts
44export default async function () {
45// Scheduled task code
46}
5657```ts
58export default async function (email: Email) {
59// Process email
60}
66## Val Town Standard Libraries
6768Val Town provides several hosted services and utility functions.
6970### Blob Storage
120```
121122## Val Town Utility Functions
123124Val Town provides several utility functions to help with common project tasks.
125126### Importing Utilities
200โ โโโ database/
201โ โ โโโ migrations.ts # Schema definitions
202โ โ โโโ queries.ts # DB query functions
203โ โ โโโ README.md
204โ โโโ routes/ # Route modules
219โโโ shared/
220โโโ README.md
221โโโ utils.ts # Shared types and functions
222```
223226- Hono is the recommended API framework
227- Main entry point should be `backend/index.ts`
228- **Static asset serving:** Use the utility functions to read and serve project files:
229```ts
230import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
260- Run migrations on startup or comment out for performance
261- Change table names when modifying schemas rather than altering
262- Export clear query functions with proper TypeScript typing
263264## Common Gotchas and Solutions
Natindex.html4 matches
507<li><a href="#" class="text-gray-400 hover:text-white transition">Birthday Parties</a></li>
508<li><a href="#" class="text-gray-400 hover:text-white transition">Private Events</a></li>
509<li><a href="#" class="text-gray-400 hover:text-white transition">Corporate Functions</a></li>
510<li><a href="#" class="text-gray-400 hover:text-white transition">Photography Services</a></li>
511<li><a href="#" class="text-gray-400 hover:text-white transition">Catering Coordination</a></li>
527<script>
528// Booking form submission
529document.getElementById('bookingForm').addEventListener('submit', async function(e) {
530e.preventDefault();
531
573
574// Contact form submission
575document.getElementById('contactForm').addEventListener('submit', function(e) {
576e.preventDefault();
577
589// Smooth scrolling for navigation links
590document.querySelectorAll('a[href^="#"]').forEach(anchor => {
591anchor.addEventListener('click', function(e) {
592e.preventDefault();
593
1export default async function (req: Request): Promise<Response> {
2// fake data API
3return Response.json([
11const API_URL = "https://jxnblk--bc1e880c319511f0bf2d569c3dd06744.web.val.run";
1213function HTML ({ children }: {
14children: React.ReactNode;
15}) {
26}
2728function Layout () {
29return (
30<HTML>
52}
5354function Home () {
55const [count, setCount] = React.useState(0);
56return (
63}
6465function About () {
66const data = useLoaderData();
67
74}
7576async function catsLoader () {
77const data = await fetch(API_URL)
78.then(res => res.json());
beeGPTfrontend.html13 matches
369<script>
370document.addEventListener('DOMContentLoaded', () => {
371// Tab switching functionality
372const chatTab = document.getElementById('chat-tab');
373const imageTab = document.getElementById('image-tab');
389});
390
391// Chat functionality
392const chatForm = document.getElementById('chat-form');
393const userInput = document.getElementById('user-input');
394const chatContainer = document.getElementById('chat-container');
395
396// Function to add a message to the chat
397function addMessage(content, isUser = false) {
398const messageDiv = document.createElement('div');
399messageDiv.className = `message-bubble ${isUser ? 'user-message' : 'ai-message'} p-4 shadow-sm`;
403}
404
405// Function to show loading indicator in chat
406function showChatLoading() {
407const loadingDiv = document.createElement('div');
408loadingDiv.id = 'loading-indicator';
413}
414
415// Function to remove loading indicator from chat
416function hideChatLoading() {
417const loadingIndicator = document.getElementById('loading-indicator');
418if (loadingIndicator) {
463});
464
465// Image Generator functionality
466const imageForm = document.getElementById('image-form');
467const imagePrompt = document.getElementById('image-prompt');
477const errorTryAgain = document.getElementById('error-try-again');
478
479// Function to reset the image generator form
480function resetImageGenerator() {
481imageResult.style.display = 'none';
482imageForm.style.display = 'block';
517const img = new Image();
518
519img.onload = function() {
520// Display the generated image
521generatedImage.src = data.imageUrl;
528};
529
530img.onerror = function() {
531// Show error if image can't be loaded
532imageLoading.style.display = 'none';
11const CLIENT_MODULE = import.meta.resolve("./client.tsx");
1213export default async function (req: Request): Promise<Response> {
14const { query, dataRoutes } = createStaticHandler(routes);
15const context = await query(req);