Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete the integration of TypeScript with Redux #72

Merged
merged 5 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
263 changes: 0 additions & 263 deletions src/App.jsx

This file was deleted.

133 changes: 133 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import axios from 'axios';
import React, { useEffect, useState } from 'react';
import ReactGA from 'react-ga4';
import { useDispatch } from 'react-redux';
import { useLocation, Outlet } from 'react-router-dom';

Check warning on line 5 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L1-L5

Added lines #L1 - L5 were not covered by tests

import { CAMPAIGN_KEY, STORAGE_KEY } from '@/const';
import Header from '@/common/guideline/components/Header';
import BannerPopup from '@/common/components/popup/bannerPopup/BannerPopup';
import CampaignPopupImage from '@/features/campaign/components/popup/CampaignPopupImage';
import PopupMenu from '@/features/campaign/components/popup/PopupMenu';
import { setIsPortrait, setSemesters, setTracks, setUser } from '@/redux/actions/common';

Check warning on line 12 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L7-L12

Added lines #L7 - L12 were not covered by tests

const App: React.FC = () => {
const dispatch = useDispatch();
const location = useLocation();
const [popupOpen, setPopupOpen] = useState(localStorage.getItem(STORAGE_KEY) !== CAMPAIGN_KEY);
const portraitMediaQuery = window.matchMedia('(max-aspect-ratio: 4/3)');

Check warning on line 18 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L14-L18

Added lines #L14 - L18 were not covered by tests

useEffect(() => {
ReactGA.send({ hitType: 'pageview', page: location.pathname });

Check warning on line 21 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L20-L21

Added lines #L20 - L21 were not covered by tests
}, [location]);

useEffect(() => {
fetchUser();
fetchSemesters();
updateSizeProperty();
window.addEventListener('resize', updateSizeProperty);
updateIsPortrait();
portraitMediaQuery.addEventListener('change', updateIsPortrait);
return () => {
window.removeEventListener('resize', updateSizeProperty);
portraitMediaQuery.removeEventListener('change', updateIsPortrait);

Check warning on line 33 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L24-L33

Added lines #L24 - L33 were not covered by tests
};
}, []);

const fetchUser = () => {
axios

Check warning on line 38 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L37-L38

Added lines #L37 - L38 were not covered by tests
.get('/session/info', {
metadata: {
gaCategory: 'User',
gaVariable: 'Get / Instance',
},
})
.then((response) => {
dispatch(setUser(response.data));

Check warning on line 46 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L45-L46

Added lines #L45 - L46 were not covered by tests
})
.catch((error) => {

Check warning on line 48 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L48

Added line #L48 was not covered by tests
if (error.response && error.response.status === 401) {
dispatch(setUser(null));

Check warning on line 50 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L50

Added line #L50 was not covered by tests
}
});
};

const fetchSemesters = () => {
axios

Check warning on line 56 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L55-L56

Added lines #L55 - L56 were not covered by tests
.get('/api/semesters', {
params: {
order: ['year', 'semester'],
},
metadata: {
gaCategory: 'Semester',
gaVariable: 'GET / List',
},
})
.then((response) => {
dispatch(setSemesters(response.data));

Check warning on line 67 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L66-L67

Added lines #L66 - L67 were not covered by tests
})
.catch(() => {});

Check warning on line 69 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L69

Added line #L69 was not covered by tests

axios

Check warning on line 71 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L71

Added line #L71 was not covered by tests
.get('/api/tracks', {
params: {},
metadata: {
gaCategory: 'Track',
gaVariable: 'GET / List',
},
})
.then((response) => {
dispatch(setTracks(response.data));

Check warning on line 80 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L79-L80

Added lines #L79 - L80 were not covered by tests
})
.catch(() => {});

Check warning on line 82 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L82

Added line #L82 was not covered by tests
};

const updateSizeProperty = () => {
document.documentElement.style.setProperty('--window-inner-height', `${window.innerHeight}px`);

Check warning on line 86 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L85-L86

Added lines #L85 - L86 were not covered by tests
};

const updateIsPortrait = () => {
dispatch(setIsPortrait(portraitMediaQuery.matches));

Check warning on line 90 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L89-L90

Added lines #L89 - L90 were not covered by tests
};

const setDoNotShow = (state: boolean) => {

Check warning on line 93 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L93

Added line #L93 was not covered by tests
if (state) {
// setDoNotShowAgain(true);
localStorage.setItem(STORAGE_KEY, CAMPAIGN_KEY);
} else {

Check warning on line 97 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L96-L97

Added lines #L96 - L97 were not covered by tests
// setDoNotShowAgain(false);
localStorage.removeItem(STORAGE_KEY);

Check warning on line 99 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L99

Added line #L99 was not covered by tests
}
};

return (

Check warning on line 103 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L103

Added line #L103 was not covered by tests
<>
<Header />
<Outlet />
<section>
<BannerPopup popupOpen={popupOpen} setPopupOpen={setPopupOpen}>
<CampaignPopupImage closePopup={() => setPopupOpen(false)} />

Check warning on line 109 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L109

Added line #L109 was not covered by tests
<PopupMenu
onClose={() => {
ReactGA.event({

Check warning on line 112 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L111-L112

Added lines #L111 - L112 were not covered by tests
category: 'Campaign',
action: 'popup-close',
});
setPopupOpen(false);

Check warning on line 116 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L116

Added line #L116 was not covered by tests
}}
onDoNotShow={() => {
ReactGA.event({

Check warning on line 119 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L118-L119

Added lines #L118 - L119 were not covered by tests
category: 'Campaign',
action: 'popup-do-not-show',
});
setDoNotShow(true);
setPopupOpen(false);

Check warning on line 124 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L123-L124

Added lines #L123 - L124 were not covered by tests
}}
/>
</BannerPopup>
</section>
</>
);
};

export default App;

Check warning on line 133 in src/App.tsx

View check run for this annotation

Codecov / codecov/patch

src/App.tsx#L133

Added line #L133 was not covered by tests
Loading
Loading