OpenTownieChat.tsx1 match
29const [isDragging, setIsDragging] = useState(false);
3031// Use custom hook to fetch project files
32const {
33projectFiles,
OpenTownieBranchControl.tsx22 matches
30const [showCreateBranch, setShowCreateBranch] = useState<boolean>(false);
3132// Fetch branches when project changes
33useEffect(() => {
34if (!projectId) return;
3536const fetchBranches = async () => {
37setIsLoadingBranches(true);
38try {
39const response = await fetch(`/api/project-branches?projectId=${projectId}`, {
40headers: {
41"Authorization": `Bearer ${bearerToken}`,
4445if (!response.ok) {
46throw new Error(`Failed to fetch branches: ${response.statusText}`);
47}
4849const data = await response.json();
50const fetchedBranches = data.branches || [];
51setBranches(fetchedBranches);
5253// Check if the stored branchId is valid for this project
54const storedBranchIsValid = fetchedBranches.some((branch: Branch) => branch.id === branchId);
5556// Only set a new branchId if there isn't a valid one already stored
57if (!storedBranchIsValid && fetchedBranches.length > 0) {
58// If branches are loaded and there's a "main" branch, select it by default
59const mainBranch = fetchedBranches.find((branch: Branch) => branch.name === "main");
60if (mainBranch) {
61setBranchId(mainBranch.id);
63} else {
64// Otherwise select the first branch
65setBranchId(fetchedBranches[0].id);
66setSelectedBranchName(fetchedBranches[0].name);
67}
68} else if (storedBranchIsValid) {
69// Set the selected branch name based on the stored branchId
70const selectedBranch = fetchedBranches.find((branch: Branch) => branch.id === branchId);
71if (selectedBranch) {
72setSelectedBranchName(selectedBranch.name);
74}
75} catch (error) {
76console.error("Error fetching branches:", error);
77} finally {
78setIsLoadingBranches(false);
80};
8182fetchBranches();
83}, [projectId, bearerToken, branchId, setBranchId]);
84105// Refresh the branches list
106if (projectId) {
107const fetchBranches = async () => {
108try {
109const response = await fetch(`/api/project-branches?projectId=${projectId}`, {
110headers: {
111"Authorization": `Bearer ${bearerToken}`,
114115if (!response.ok) {
116throw new Error(`Failed to fetch branches: ${response.statusText}`);
117}
118119const data = await response.json();
120const fetchedBranches = data.branches || [];
121setBranches(fetchedBranches);
122123// Update the selected branch name
124const selectedBranch = fetchedBranches.find((branch: Branch) => branch.id === newBranchId);
125if (selectedBranch) {
126setSelectedBranchName(selectedBranch.name);
127}
128} catch (error) {
129console.error("Error fetching branches:", error);
130}
131};
132133fetchBranches();
134}
135};
OpenTownieapi.ts3 matches
1// Fetch project files from the backend
2export async function fetchProjectFiles(
3{ bearerToken, projectId, branchId }: { bearerToken: string; projectId: string; branchId?: string },
4) {
9}
1011const response = await fetch(url.toString(), {
12headers: {
13"Authorization": "Bearer " + bearerToken,
Staff_Chatroommain.tsx9 matches
35const [isLoggedIn, setIsLoggedIn] = useState(false);
3637// Fetch messages periodically
38useEffect(() => {
39if (isLoggedIn) {
40const fetchMessages = async () => {
41try {
42const response = await fetch('/messages');
43const result = await response.json();
44if (result.ok) {
46}
47} catch (error) {
48console.error('Failed to fetch messages');
49}
50};
5152fetchMessages();
53const intervalId = setInterval(fetchMessages, 5000);
54return () => clearInterval(intervalId);
55}
58const handleRegister = async () => {
59try {
60const response = await fetch('/register', {
61method: 'POST',
62headers: { 'Content-Type': 'application/json' },
82const handleLogin = async () => {
83try {
84const response = await fetch('/login', {
85method: 'POST',
86headers: { 'Content-Type': 'application/json' },
113114try {
115const response = await fetch('/send-message', {
116method: 'POST',
117headers: { 'Content-Type': 'application/json' },
JaanWebsiteStatusmonitor2 matches
15const start = performance.now();
16try {
17res = await fetch(url);
18end = performance.now();
19status = res.status;
25} catch (e) {
26end = performance.now();
27reason = `couldn't fetch: ${e}`;
28ok = false;
29}
40});
4142// Fetch products on component mount
43useEffect(() => {
44fetch(import.meta.url, { method: 'GET' })
45.then(response => response.json())
46.then(data => setProducts(data.products));
82e.preventDefault();
83try {
84const response = await fetch(import.meta.url, {
85method: 'POST',
86headers: { 'Content-Type': 'application/json' },
296}
297298// Handle GET request to fetch products
299if (request.method === 'GET') {
300const productsResult = await sqlite.execute(`SELECT * FROM ${KEY}_products`);
timeTrackerAppmain.tsx8 matches
12useEffect(() => {
13const timer = setInterval(() => setCurrentTime(new Date()), 1000);
14fetchRecentRecords();
15return () => clearInterval(timer);
16}, []);
1718const fetchRecentRecords = async () => {
19try {
20const response = await fetch('/recent-records');
21const records = await response.json();
22setRecentRecords(records);
23} catch (error) {
24console.error('Failed to fetch recent records', error);
25}
26};
3334try {
35const response = await fetch('/clock-action', {
36method: 'POST',
37headers: {
43setStatus(result.status);
44setLastClockIn(result.timestamp);
45fetchRecentRecords();
46} catch (error) {
47console.error('Clock action failed', error);
51const handleExportToExcel = async () => {
52try {
53const response = await fetch('/export-excel');
54const blob = await response.blob();
55const url = window.URL.createObjectURL(blob);
173}
174175// Fetch recent records
176if (request.method === 'GET' && new URL(request.url).pathname === '/recent-records') {
177const recentRecords = await sqlite.execute(`
englishways_migratedmain.tsx7 matches
2021useEffect(() => {
22fetch('/username')
23.then(response => response.text())
24.then(name => {
25if (name) {
26setUsername(name);
27fetchArticles();
28}
29});
30}, []);
3132const fetchArticles = () => {
33fetch('/articles')
34.then(response => response.json())
35.then(data => setArticles(data));
46const handleUsernameSubmit = () => {
47if (editingUsername.trim()) {
48fetch('/username', {
49method: 'POST',
50body: editingUsername.trim()
54setUsername(name);
55setShowWelcome(false);
56fetchArticles();
57});
58}
66const handleUsernameSave = () => {
67if (editingUsername.trim()) {
68fetch('/username', {
69method: 'POST',
70body: editingUsername.trim()
shiftSchedulermain.tsx7 matches
1314useEffect(() => {
15fetchShifts();
16}, []);
1718const fetchShifts = async () => {
19const response = await fetch("/shifts");
20const data = await response.json();
21setShifts(data);
29const addShift = async (e) => {
30e.preventDefault();
31await fetch("/shifts", {
32method: "POST",
33headers: { "Content-Type": "application/json" },
34body: JSON.stringify(newShift)
35});
36fetchShifts();
37setNewShift({ employeeName: "", date: "", startTime: "", endTime: "" });
38};
3940const deleteShift = async (id) => {
41await fetch(`/shifts/${id}`, { method: "DELETE" });
42fetchShifts();
43};
44
116117try {
118const response = await fetch("/submit-contact", {
119method: "POST",
120headers: {