Skip to content

Commit

Permalink
Implement redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
avgupta456 committed Nov 27, 2023
1 parent fcd28a7 commit 1c02a51
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions frontend/src/pages/App/AppTrends.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import { setPrivateAccess as _setPrivateAccess } from '../../redux/actions/userA
import { getUserMetadata } from '../../api';
import { WRAPPED_URL } from '../../constants';
import Footer from './Footer';
import { SelectUserScreen, WrappedScreen } from '../Wrapped';

function WrappedAuthRedirectScreen() {
// for wrapped auth redirects
const { rest } = useParams();
useEffect(() => {
const code = new URLSearchParams(window.location.search).get('code');
Expand All @@ -34,6 +34,22 @@ function WrappedAuthRedirectScreen() {
return null;
}

function WrappedRedirectScreen() {
// redirects /wrapped/* to https://www.githubwrapped.com/*
const { userId, year } = useParams();
useEffect(() => {
if (userId) {
if (year) {
window.location.href = `${WRAPPED_URL}/${userId}/${year}`;
} else {
window.location.href = `${WRAPPED_URL}/${userId}`;
}
} else {
window.location.href = `${WRAPPED_URL}/`;
}
}, [userId, year]);
}

function App() {
const userId = useSelector((state) => state.user.userId);
const isAuthenticated = userId && userId.length > 0;
Expand Down Expand Up @@ -69,13 +85,19 @@ function App() {
element={<WrappedAuthRedirectScreen />}
/>
<Route path="/user/*" element={<HomeScreen />} />
<Route path="/wrapped/:userId/:year" element={<WrappedScreen />} />
<Route path="/wrapped/:userId" element={<WrappedScreen />} />
<Route path="/wrapped" element={<SelectUserScreen />} />
<Route
path="/wrapped/:userId/:year"
element={<WrappedRedirectScreen />}
/>
<Route
path="/wrapped/:userId"
element={<WrappedRedirectScreen />}
/>
<Route path="/wrapped" element={<WrappedRedirectScreen />} />
{isAuthenticated && (
<Route path="/settings" element={<SettingsScreen />} />
)}
<Route path="/:userId" element={<WrappedScreen />} />
<Route path="/:userId" element={<WrappedRedirectScreen />} />
<Route exact path="/" element={<LandingScreen />} />
<Route path="*" element={<NoMatchScreen />} />
</Routes>
Expand Down

0 comments on commit 1c02a51

Please sign in to comment.