Skip to content

Commit

Permalink
Merge pull request #23 from daithihearn/updating-curr-price
Browse files Browse the repository at this point in the history
fix: updating current price with the need for a page refresh
  • Loading branch information
daithihearn authored Feb 8, 2024
2 parents ab8582e + f4a8d6e commit c0a31fa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "daithi-dashboard",
"version": "2.10.0",
"version": "2.10.1",
"private": true,
"dependencies": {
"@emotion/react": "^11.11.3",
Expand Down
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"sizes": "512x512"
}
],
"version": "2.10.0",
"version": "2.10.1",
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
Expand Down
6 changes: 3 additions & 3 deletions src/components/PriceChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const PriceChart: React.FC<PriceChartProps> = ({

useEffect(() => {
if (!showCurrentPrice || prices.length <= 1) return
// Function to be executed every minute

const updateData = () => {
if (!showCurrentPrice || prices.length <= 1) return

Expand All @@ -71,8 +71,8 @@ const PriceChart: React.FC<PriceChartProps> = ({
// Run the function on component load
updateData()

// Set the interval to run the function every minute
const intervalId = setInterval(updateData, 10 * 60 * 1000)
// Set the interval to run the function every 5 minutes
const intervalId = setInterval(updateData, 5 * 60 * 1000)

// Cleanup function to clear the interval when the component is unmounted
return () => {
Expand Down
16 changes: 15 additions & 1 deletion src/pages/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useState } from "react"
import React, { useCallback, useEffect, useState } from "react"
import Box from "@mui/material/Box"
import Typography from "@mui/material/Typography"
import Paper from "@mui/material/Paper"
Expand Down Expand Up @@ -76,5 +76,19 @@ const DashboardContent: React.FC = () => {
}

export default function Dashboard() {
// At the start of every hour we want to refetch the data
const { now } = useDateTime()
useEffect(() => {
const intervalId = setInterval(() => {
if (now().minute === 0) {
window.location.reload()
}
}, 35 * 1000)

return () => {
clearInterval(intervalId)
}
}, [now])

return <DashboardContent />
}

0 comments on commit c0a31fa

Please sign in to comment.