Skip to content

Commit

Permalink
fix: bug page not refreshed
Browse files Browse the repository at this point in the history
  • Loading branch information
mgierada committed Jun 14, 2024
1 parent 6cb8c35 commit c057fef
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
24 changes: 22 additions & 2 deletions ui/src/app/page.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
import axios from "axios";
import CounterDisplay from "@/components/CounterDisplay";

const Home = () => {
const fetchCounter = async () => {
try {
const rootUrl = process.env.NEXT_PUBLIC_ROOT_API_URL;
const endpoint = `${rootUrl}/counter`;

const response = await axios.get(endpoint);
if (response.data && typeof response.data.CurrentValue === "number") {
return { currentValue: response.data.CurrentValue, error: null };
} else {
throw new Error("Invalid response data");
}
} catch (error) {
console.error("Error fetching the current value:", error.message); // Debug log
return { currentValue: null, error: "Failed to fetch current value" };
}
};

const Home = async () => {
const { currentValue, error } = await fetchCounter();

return (
<main className="flex min-h-screen flex-col items-center justify-between p-24">
<div className="z-10 max-w-5xl w-full items-center justify-between font-mono text-sm lg:flex"></div>

<div className="relative flex place-items-center before:absolute before:h-[300px] before:w-full sm:before:w-[480px] before:-translate-x-1/2 before:rounded-full before:bg-gradient-radial before:from-white before:to-transparent before:blur-2xl before:content-[''] after:absolute after:-z-20 after:h-[180px] after:w-full sm:after:w-[240px] after:translate-x-1/3 after:bg-gradient-conic after:from-sky-200 after:via-blue-200 after:blur-2xl after:content-[''] before:dark:bg-gradient-to-br before:dark:from-transparent before:dark:to-blue-700 before:dark:opacity-10 after:dark:from-sky-900 after:dark:via-[#0141ff] after:dark:opacity-40 before:lg:h-[360px] z-[-1]">
<CounterDisplay />
<CounterDisplay currentValue={currentValue} error={error} />
</div>
<div></div>
</main>
Expand Down
23 changes: 1 addition & 22 deletions ui/src/components/CounterDisplay/index.jsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
import axios from "axios";

const fetchCurrentValue = async () => {
try {
const rootUrl = process.env.NEXT_PUBLIC_ROOT_API_URL;
const endpoint = `${rootUrl}/counter`;

const response = await axios.get(endpoint);
if (response.data && typeof response.data.CurrentValue === "number") {
return { currentValue: response.data.CurrentValue, error: null };
} else {
throw new Error("Invalid response data");
}
} catch (error) {
console.error("Error fetching the current value:", error.message); // Debug log
return { currentValue: null, error: "Failed to fetch current value" };
}
};

const CounterDisplay = async () => {
const { currentValue, error } = await fetchCurrentValue();

const CounterDisplay = ({ currentValue, error }) => {
return (
<div>
{error ? (
Expand Down

0 comments on commit c057fef

Please sign in to comment.