TownieHeader.tsx7 matches
8import CreditBalance from "./CreditBalance.tsx";
910export function Header () {
11const navigate = useNavigate();
12const { user } = useContext(AppContext);
26}
2728function Dropdown () {
29const { user } = useContext(AppContext);
30const { ref, open, setOpen } = useDropdown();
54}
5556function useDropdown() {
57const [open, setOpen] = useState(false);
58const ref = useRef(null);
72}
7374function Avatar ({ user }) {
75if (!user?.profileImageUrl) {
76return (
90}
9192function LogOut () {
93const { user } = useContext(AppContext);
94return (
101}
102103function DarkButton () {
104const [dark, setDark] = useLocalStorage("DARK_MODE", false);
105const toggle = () => {
127}
128129function AudioButton () {
130const {audio, setAudio} = useContext(AppContext);
131
Townieformatters.ts1 match
1// Utility functions for formatting data in the dashboard
23/**
TownieFooter.tsx1 match
4const SOURCE_URL = "https://val.town/x/valdottown/Townie";
56export function Footer () {
7return (
8<footer className="container footer">
1export default function fileWithLineNumbers(text: string, view_range) {
2const lines = text.split("\n")
3.map((line, index) => (index + 1) + ": " + line)
Towniefavicon.http.tsx1 match
3import { TownieIcon } from "./components/icons.tsx";
45export default async function (loading: boolean) {
6const svg = renderToString(
7<TownieIcon color="#ffffff" circle={loading ? "#0EA5E9" : "#000000"} />
TownieDebugStyles.tsx1 match
4import { Messages } from "./Messages.tsx";
56export function DebugStyles() {
7const [pathname, setPathname] = useState("");
8return (
Towniedashboard.ts1 match
16}
1718export function renderDashboard(data: UserSummaryRow[]): string {
19// Calculate totals
20const totalUsers = data.length;
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
TownieCreditBalance.tsx1 match
3import { Link } from "react-router";
45export default function CreditBalance() {
6const [balance, setBalance] = useState<number | null>(null);
7const [loading, setLoading] = useState(true);
Towniecredit-additions.ts2 matches
12* Render the credit additions page
13*/
14export function renderCreditAdditions(
15data: CreditAddition[],
16pagination: PaginationResult,
100activeTab: "credit-additions",
101scripts: [`
102document.addEventListener('DOMContentLoaded', function() {
103// Date inputs initialization
104const today = new Date();