Skip to content

Commit

Permalink
Merge pull request #4 from ashortsleeves/develop
Browse files Browse the repository at this point in the history
fetch data from heckdivers-json github repo.
  • Loading branch information
ashortsleeves authored May 7, 2024
2 parents 843aa18 + ffb082c commit b4ee238
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
39 changes: 18 additions & 21 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ import NewsFeed from './components/NewsFeed';
import StaticBG from './components/StaticBG';
import DefaultZoomTools from './components/DefaultZoomTools';
import planetsData from './planets.json';
import campaignsData from './campaigns.json';
import grid from './assets/grid.webp';
import reloadImg from './assets/reload.svg'
import saturnImg from './assets/planet-space-icon.svg';

import { TransformWrapper, TransformComponent } from 'react-zoom-pan-pinch';
const headers = {"X-Super-Client": "Heckdivers", "X-Super-Contact": "gh/ashortsleeves"}

function App() {
// const [campaigns, setCampaigns] = useState([]);
const [campaigns, setCampaigns] = useState([]);
const planets = planetsData;
const campaigns = campaignsData;
const [isRotating, setIsRotating] = useState(false);

const toggleRotation = () => {
Expand All @@ -29,24 +26,24 @@ function App() {
}

// Fetch data from APIs and update state
// const fetchData = async () => {
// try {
// const campaignsResponse = await fetch('https://api.helldivers2.dev/api/v1/campaigns', {headers: headers});
// const campaignsData = await campaignsResponse.json();
// setCampaigns(campaignsData);

// } catch (error) {
// console.error('Error fetching data:', error);
// }
// };
const fetchData = async () => {
try {
const campaignsResponse = await fetch('https://raw.githubusercontent.com/ashortsleeves/heckdivers-json/main/campaigns.json');
const campaignsData = await campaignsResponse.json();
setCampaigns(campaignsData);
console.log("fetching campaign data: " + new Date().toString());
} catch (error) {
console.error('Error fetching data:', error);
}
};

// Fetch data on component mount and every minute
// useEffect(() => {
// fetchData(); // Fetch data initially
// const intervalId = setInterval(fetchData, 10000); // Fetch data every minute
// console.log('fetch data attempt')
// return () => clearInterval(intervalId);
// }, []);
useEffect(() => {
fetchData(); // Fetch data initially
const intervalId = setInterval(fetchData, 600000); // Fetch data every minute

return () => clearInterval(intervalId);
}, []);


function handleZoomClick(targetButtonID) {
Expand Down Expand Up @@ -108,7 +105,7 @@ function App() {
</TransformWrapper>
</div>

{/* <NewsFeed/> */}
<NewsFeed/>
{planets.length <= 0 || campaigns.length <= 0 ? <div className='planets-loading'><h2>CONNECTING TO SUPER EARTH</h2></div> : ''}
<div className='button-controls'>
<button onClick={() => handleZoomClick('zIn')}>+ <span>Zoom In</span></button>
Expand Down
10 changes: 4 additions & 6 deletions src/components/NewsFeed.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ export default function NewsFeed() {
const [newsFeed, setNewsFeed] = useState([]);
const [majorOrder, setMajorOrder] = useState([]);
const [activeIndex, setActiveIndex] = useState(0); // Keep track of the index of the active component
const headers = {"X-Super-Client": "Heckdivers", "X-Super-Contact": "gh/ashortsleeves"}

const fetchData = async () => {
try {
const majorOrderResponse = await fetch('https://api.helldivers2.dev/api/v1/assignments', {headers: headers});
const majorOrderResponse = await fetch('https://raw.githubusercontent.com/ashortsleeves/heckdivers-json/main/assignments.json');
const majorOrderData = await majorOrderResponse.json();
setMajorOrder(majorOrderData);

const newsFeedResponse = await fetch('https://api.helldivers2.dev/raw/api/NewsFeed/801', {headers: headers});
const newsFeedResponse = await fetch('https://raw.githubusercontent.com/ashortsleeves/heckdivers-json/main/newsfeed.json');
const newsFeedData = await newsFeedResponse.json();
setNewsFeed(newsFeedData);

console.log("fetching assignments and newsfeed: " + new Date().toString());
} catch (error) {
console.error('Error fetching data:', error);
}
Expand All @@ -25,8 +24,7 @@ export default function NewsFeed() {
// Fetch data on component mount and every minute
useEffect(() => {
fetchData(); // Fetch data initially
const intervalId = setInterval(fetchData, 10000); // Fetch data every minute
console.log('fetch newsfeed')
const intervalId = setInterval(fetchData, 600000); // Fetch data every minute
return () => clearInterval(intervalId);
}, []);

Expand Down

0 comments on commit b4ee238

Please sign in to comment.