43
44 try {
45 const response = await fetch("/chat", {
46 method: "POST",
47 body: JSON.stringify({
59
60 useEffect(() => {
61 const fetchMessages = async () => {
62 try {
63 const response = await fetch("/chat");
64 const messages = await response.json();
65 setChatMessages(messages);
66 } catch (error) {
67 console.error("Fetch messages error:", error);
68 }
69 };
70 fetchMessages();
71 }, [mood]);
72
43
44 try {
45 const response = await fetch("/chat", {
46 method: "POST",
47 body: JSON.stringify({
59
60 useEffect(() => {
61 const fetchMessages = async () => {
62 try {
63 const response = await fetch("/chat");
64 const messages = await response.json();
65 setChatMessages(messages);
66 } catch (error) {
67 console.error("Fetch messages error:", error);
68 }
69 };
70 fetchMessages();
71 }, [mood]);
72
70 // Save to backend
71 try {
72 const response = await fetch('/save-schedule', {
73 method: 'POST',
74 headers: { 'Content-Type': 'application/json' },
103 // Save to backend
104 try {
105 const response = await fetch('/save-schedule', {
106 method: 'POST',
107 headers: { 'Content-Type': 'application/json' },
122 // Update backend
123 try {
124 const response = await fetch('/save-schedule', {
125 method: 'POST',
126 headers: { 'Content-Type': 'application/json' },
149 // Update backend
150 try {
151 const response = await fetch('/save-schedule', {
152 method: 'POST',
153 headers: { 'Content-Type': 'application/json' },
163
164 useEffect(() => {
165 // Fetch existing schedule on component mount
166 const fetchSchedule = async () => {
167 try {
168 const response = await fetch('/get-schedule');
169 const savedData = await response.json();
170 if (savedData) {
173 }
174 } catch (error) {
175 console.error('Failed to fetch schedule', error);
176 }
177 };
178
179 fetchSchedule();
180 }, []);
181
43
44 try {
45 const response = await fetch("/chat", {
46 method: "POST",
47 body: JSON.stringify({
59
60 useEffect(() => {
61 const fetchMessages = async () => {
62 try {
63 const response = await fetch("/chat");
64 const messages = await response.json();
65 setChatMessages(messages);
66 } catch (error) {
67 console.error("Fetch messages error:", error);
68 }
69 };
70 fetchMessages();
71 }, [mood]);
72
1const baseUrl = "https://api.neynar.com/v2/farcaster/";
2
3export async function fetchNeynarGet(path: string) {
4 const res = await fetch(baseUrl + path, {
5 method: "GET",
6 headers: {
14}
15
16export function fetchUser(username: string) {
17 return fetchNeynarGet(`user/by_username?username=${username}`).then(r => r.user);
18}
19export function fetchUsersById(fids: string) {
20 return fetchNeynarGet(`user/bulk?fids=${fids}`).then(r => r.users);
21}
22
23export function fetchUserFeed(fid: number) {
24 return fetchNeynarGet(
25 `feed?feed_type=filter&filter_type=fids&fids=${fid}&with_recasts=false&with_replies=false&limit=100&cursor=`,
26 ).then(r => r.casts);
27}
28
29export function fetchChannel(channelId: string) {
30 return fetchNeynarGet(`channel?id=${channelId}`).then(r => r.channel);
31}
32
33export function fetchChannelFeed(channelId: string) {
34 return fetchNeynarGet(
35 `feed/channels?channel_ids=${channelId}&with_recasts=false&limit=100`,
36 ).then(r => r.casts);
37}
38
39export function fetchChannelsFeed(channelIds: array) {
40 return fetchNeynarGet(
41 `feed/channels?channel_ids=${channelIds.join(",")}&with_recasts=false&limit=100`,
42 ).then(r => r.casts);
63});
64
65// HTTP vals expect an exported "fetch handler"
66// This is how you "run the server" in Val Town with Hono
67export default app.fetch;
75 const fontPromises = fontsConfig.map(async (font) => {
76 const fontUrl = "https://cdn.jsdelivr.net/npm/@tamagui/font-inter@1.108.3/otf/" + font.fontFile;
77 const fontArrayBuf = await fetch(fontUrl).then((res) => res.arrayBuffer());
78 return { name: font.name, data: fontArrayBuf, weight: font.weight };
79 });
86 // const api = `https://cdnjs.cloudflare.com/ajax/libs/twemoji/14.0.2/svg/${code.toLowerCase()}.svg`
87 const api = `https://cdn.jsdelivr.net/gh/shuding/fluentui-emoji-unicode/assets/${code.toLowerCase()}_color.svg`;
88 return fetch(api).then((r) => r.text());
89};
90
7
8import { Button, Input, Section } from "../components/ui.tsx";
9import { fetchUsersById } from "../util/neynar.ts";
10
11export function Home() {
41
42async function sendNotification(notificationDetails: any, payload: any) {
43 return await fetch(notificationDetails.url, {
44 method: "POST",
45 headers: { "Content-Type": "application/json" },
8import { FarcasterMiniApp } from "./components/FarcasterMiniApp.tsx";
9import { Button, Section } from "./components/ui.tsx";
10import { fetchNeynarGet } from "./util/neynar.ts";
11
12export function App() {
67
68function Database() {
69 const queryFn = () => fetch("/api/counter/get").then((r) => r.json());
70 const { data, refetch } = useQuery({ queryKey: ["counter"], queryFn });
71 return (
72 <Section className="flex flex-col items-start gap-3 m-5">
73 {/* <h2 className="font-semibold">Database Example</h2> */}
74 <div className="">Counter value: {data}</div>
75 <Button variant="outline" onClick={() => fetch("/api/counter/increment").then(refetch)}>
76 Increment
77 </Button>
82function Neynar() {
83 useEffect(() => {
84 fetchNeynarGet("user/by_username?username=moe").then(console.log).catch(console.error);
85 }, []);
86