Skip to content

Commit

Permalink
Merge pull request #25 from pehlicd/9-fix-frontend-fetch-method-shoul…
Browse files Browse the repository at this point in the history
…d-be-configurable-over-cli-since-we-support-port-configuration

fix(ui): switched to axios and removed port dependency in ui
  • Loading branch information
pehlicd authored May 18, 2024
2 parents 00fb061 + 92e44c5 commit 9124c6e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 14 deletions.
40 changes: 40 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Ignore everything
*

# But not these files...
!/.gitignore

!*.go
!go.sum
!go.mod

!README.md
!LICENSE

!ui/app/*
!ui/components/*
!ui/config/*
!ui/public/*
!ui/styles/*
!ui/types/*
!ui/.eslintrc.json
!ui/.npmrc
!ui/LICENSE
!ui/next.config.js
!ui/next-env.d.ts
!ui/package.json
!ui/postcss.config.js
!ui/tailwind.config.js
!ui/tsconfig.json

!.github/*
!.github/workflows/*
!.github/ISSUE_TEMPLATE/*

!.goreleaser.yml

# !Makefile

# ...even if they are in subdirectories
!*/

2 changes: 1 addition & 1 deletion internal/statik/statik.go

Large diffs are not rendered by default.

13 changes: 5 additions & 8 deletions ui/components/graph.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";
import { useEffect, useRef, useState } from 'react';
import * as d3 from 'd3';
import axios from "axios";

interface Node extends d3.SimulationNodeDatum {
id: string;
Expand Down Expand Up @@ -42,15 +43,11 @@ const DisjointGraph = () => {
useEffect(() => {
const fetchData = async () => {
try {
const response = await fetch('http://localhost:8080/api/data');
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data: BindingData[] = await response.json();
const response = await axios.get('/api/data');
const data: BindingData[] = response.data;
if (!data) {
throw new Error('Data is null or undefined');
console.error(new Error('Data is null or undefined'));
}
console.log('Fetched data:', data);
renderGraph(data);
} catch (error) {
console.error('Error fetching data:', error);
Expand Down Expand Up @@ -161,7 +158,7 @@ const DisjointGraph = () => {
};
};

fetchData();
fetchData().finally(() => { console.log('Data fetching completed'); });
}, [isDarkMode]);

useEffect(() => {
Expand Down
10 changes: 5 additions & 5 deletions ui/components/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {SearchIcon, VerticalDotsIcon, ChevronDownIcon, RefreshIcon} from "@/comp
import {Modal, ModalBody, ModalContent, ModalHeader} from "@nextui-org/modal";
import {Card, CardBody, CardHeader} from "@nextui-org/card";
import { stringify } from 'yaml';
import axios from "axios";

function capitalize(str: string) {
return str.charAt(0).toUpperCase() + str.slice(1);
Expand Down Expand Up @@ -84,9 +85,8 @@ export default function MainTable() {
const hasSearchFilter = Boolean(filterValue);

useEffect(() => {
fetch('http://localhost:8080/api/data')
.then(response => response.json())
.then(data => setData(data))
axios.get('/api/data')
.then(response => setData(response.data))
.catch(error => console.error('Error fetching data:', error));
}, []);

Expand Down Expand Up @@ -165,7 +165,7 @@ export default function MainTable() {
);
case "details":
return (
<div className="relative flex justify-end items-center gap-2">
<div className="relative flex justify-center items-center gap-2">
<Dropdown>
<DropdownTrigger>
<Button isIconOnly size="sm" variant="light">
Expand Down Expand Up @@ -275,7 +275,7 @@ export default function MainTable() {
))}
</DropdownMenu>
</Dropdown>
<Button color="primary" endContent={<RefreshIcon />} onClick={() => fetch('http://localhost:8080/api/data').then(response => response.json()).then(data => setData(data)).catch(error => console.error('Error fetching data:', error))}>
<Button color="primary" endContent={<RefreshIcon />} onClick={() => axios.get('/api/data').then(response => setData(response.data)).catch(error => console.error('Error fetching data:', error))}>
Refresh
</Button>
</div>
Expand Down
1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@types/react": "18.2.21",
"@types/react-dom": "18.2.7",
"autoprefixer": "10.4.19",
"axios": "^1.6.8",
"clsx": "^2.0.0",
"d3": "^7.9.0",
"eslint": "8.48.0",
Expand Down

0 comments on commit 9124c6e

Please sign in to comment.