MiniAppStarterExample.tsx1 match
5import { ShareButton } from "./ui.tsx";
67export function Example() {
8const [context, setContext] = useState<any>();
9useEffect(() => {
logMoodindex.html1 match
96});
9798async function loadLogs() {
99logList.innerHTML = "Loading...";
100const res = await fetch(getMoodLogUrl);
ChatMessage.tsx1 match
49/* โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ */
5051export default function MessageComponent({ message, onDelete, onRetry, canRetry }: MessageProps) {
52const formatRegularContent = (content: string) => <div dangerouslySetInnerHTML={{ __html: marked(content) }}></div>;
53
thirdTimerindex.tsx1 match
17import { HelpText } from "./components/HelpText.tsx";
1819function ThirdTimeApp() {
20const [state, setState] = useState<TimerState>({
21mode: "idle",
thirdTimerutils.ts2 matches
1export function formatTime(seconds: number): string {
2const hours = Math.floor(seconds / 3600);
3const minutes = Math.floor((seconds % 3600) / 60);
12}
1314export function formatMinutes(minutes: number): string {
15if (minutes < 1) return `${Math.round(minutes * 60)}s`;
16if (minutes < 60) return `${Math.round(minutes)}m`;
thirdTimerval-town.mdc12 matches
910- Ask clarifying questions when requirements are ambiguous
11- Provide complete, functional solutions rather than skeleton implementations
12- Test your logic against edge cases before presenting the final solution
13- Ensure all code follows Val Town's specific platform requirements
22- **Never bake in secrets into the code** - always use environment variables
23- Include comments explaining complex logic (avoid commenting obvious operations)
24- Follow modern ES6+ conventions and functional programming practices if possible
2526## Types of triggers
3334```ts
35export default async function (req: Request) {
36return new Response("Hello World");
37}
4546```ts
47export default async function () {
48// Scheduled task code
49}
5758```ts
59export default async function (email: Email) {
60// Process email
61}
65## Val Town Standard Libraries
6667Val Town provides several hosted services and utility functions.
6869### Blob Storage
119```
120121## Val Town Utility Functions
122123Val Town provides several utility functions to help with common project tasks.
124125### Importing Utilities
181โ โโโ database/
182โ โ โโโ migrations.ts # Schema definitions
183โ โ โโโ queries.ts # DB query functions
184โ โ โโโ README.md
185โ โโโ routes/ # Route modules
200โโโ shared/
201โโโ README.md
202โโโ utils.ts # Shared types and functions
203```
204208- Main entry point should be `backend/index.ts`
209- Do NOT use Hono serveStatic middleware
210- **Static asset serving:** Use the utility functions to read and serve project files:
211```ts
212import { readFile, serveFile } from "https://esm.town/v/std/utils/index.ts";
242- Run migrations on startup or comment out for performance
243- Change table names when modifying schemas rather than altering
244- Export clear query functions with proper TypeScript typing
245246## Common Gotchas and Solutions
MiniAppStarterCustomHaptics.tsx4 matches
8import { Button, Input, Section, MonoButtonWithStatus } from '../components/ui.tsx'
910export function CustomHaptics() {
11const [context, setContext] = useState<any>()
1273}
7475async function hapticsPattern(pattern: string) {
76function delay(ms?: number) {
77return new Promise((resolve) => setTimeout(resolve, ms || 150))
78}
79function hapticsChar(char: string) {
80if (char === 's') return fcsdk.haptics?.notificationOccurred?.('success').then(() => delay())
81if (char === '*') return fcsdk.haptics?.impactOccurred?.('heavy').then(() => delay())
ReactHonoStarterTestsApp.tsx1 match
2import { useState } from "https://esm.sh/react@18.2.0";
34export function App() {
5const [clicked, setClicked] = useState(0);
6return (
Websocketstest2.tsx1 match
1export default function handler(req: Request) {
2if (req.headers.get("upgrade") != "websocket") {
3return new Response(null, { status: 501 });
uppsalatech25data.ts6 matches
8type Message = z.infer<typeof messageSchema>;
9type MessageWithSource = Message & { source: "email" | "sms" | "api" };
10export async function getMessages(): Promise<MessageWithSource[]> {
11let messages = await blob.getJSON(key);
12if (!messages) {
16}
17const maxMessages = 100;
18export async function addEmail(email: Email) {
19return addMessage({ message: email.text, subject: email.subject }, "email");
20}
21export async function addApiMessage(apiMessage: unknown) {
22return addMessage(apiMessage, "api");
23}
24export async function addSms(sms: unknown) {
25return addMessage(sms, "sms");
26}
27async function addMessage(
28message: unknown,
29source: "sms" | "email" | "api",
40return validMessage;
41}
42export async function clearMessages() {
43await blob.setJSON(key, []);
44}