import React, {useState, useEffect } from 'react'; import { useAtom } from 'jotai' import { serverConfigAtom } from '../../state/main'; import { HiPlus } from 'react-icons/hi' import { Loader, Center, SimpleGrid, Title, Group, Button } from '@mantine/core' import { useNavigate } from "react-router-dom"; import { useNotifications } from '@mantine/notifications'; import { backendAPI } from '../../services/backend-api'; import LocationCard from '../cards/LocationCard'; function LocationsPage() { // const [opened, setOpened] = useState(false); const [isLoading, setIsLoading] = useState(false); const [locations, setLocations] = useState([]) const [serverConfig] = useAtom(serverConfigAtom) let navigate = useNavigate(); const notifications = useNotifications(); useEffect(() => { console.log("LOADING LOCATIONS PAGE!") setIsLoading(true) async function fetchSettings() { backendAPI.get('/locations').then(results => { console.log("CONFIG IN LOCATIONS: ", serverConfig) console.log("LOCATIONS: ", results.data) setLocations(results.data) setIsLoading(false) }).catch(err => { notifications.showNotification({ title: 'Backend Notice', message: `Failed to fetch locations from backend! ${err}`, autoClose: false, color: "red", }) setIsLoading(false) }) } fetchSettings(); }, []) return ( <>
{ isLoading && }
Locations
{ locations.map((location, idx) => )} ); } export default LocationsPage;