Skip to content

Commit

Permalink
feat: fetching extra pixels a user has from the backend (#80)
Browse files Browse the repository at this point in the history
* feat: fetching extra pixels a user has from the backend

* feat: resolved PR review

* feat: removed console statement
  • Loading branch information
Ayoazeez26 authored Apr 25, 2024
1 parent 2dc9e5b commit 5e5a84e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/routes/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func InitUserRoutes() {
}

func getExtraPixels(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
user := r.URL.Query().Get("address")

var available string
Expand Down
17 changes: 17 additions & 0 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import TabPanel from './tabs/TabPanel.js';
import { usePreventZoom } from './utils/Window.js';
import logo from './resources/logo.png';
import canvasConfig from "./configs/canvas.config.json"
import backendConfig from "./configs/backend.config.json";

function App() {
// Window management
Expand All @@ -19,6 +20,7 @@ function App() {
const isDesktopOrLaptop = useMediaQuery({
query: '(min-width: 1224px)'
})
const backendUrl = "http://" + backendConfig.host + ":" + backendConfig.port;
const isBigScreen = useMediaQuery({ query: '(min-width: 1824px)' })
const isTabletOrMobile = useMediaQuery({ query: '(max-width: 1224px)' })
const isPortrait = useMediaQuery({ query: '(orientation: portrait)' })
Expand Down Expand Up @@ -54,6 +56,21 @@ function App() {
const [extraPixelsUsed, setExtraPixelsUsed] = useState(0);
const [extraPixelsData, setExtraPixelsData] = useState([]);

useEffect(() => {
const address = 0;
let getExtraPixelsEndpoint = `${backendUrl}/getExtraPixels?address=${address}`;
fetch(getExtraPixelsEndpoint, { mode: "cors" }).then((response) => {
response
.json()
.then((data) => {
setExtraPixels(data);
})
.catch((error) => {
console.error(error);
});
});
},[])

const clearPixelSelection = () => {
setSelectedPositionX(null);
setSelectedPositionY(null);
Expand Down

0 comments on commit 5e5a84e

Please sign in to comment.