Skip to content

Commit 369e3dd

Browse files
authored
Merge branch 'master' into update_modal
2 parents f610547 + afb1c8a commit 369e3dd

9 files changed

+54
-32
lines changed

src/components/Dashboard/ActiveItems.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default function ActiveItems({
7777
return (
7878
<DashboardCard>
7979
<div className="px-4 py-5 sm:p-6">
80-
<h3 className="text-lg leading-6 font-medium text-gray-900 dark:text-dark-high-emphasis">
80+
<h3 className="text-lg leading-6 font-medium text-gray-800 dark:text-dark-high-emphasis">
8181
Active {type === 'problems' ? 'Problems' : 'Modules'}
8282
</h3>
8383
<div className="mt-4 text-gray-500">

src/components/Dashboard/Activity.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export function ActivityHeatmap({
3939
(activeDate && moduleActivities[activeDate.getTime()]?.length) ?? 0;
4040
return (
4141
<div className="sm:px-6 lg:px-8 py-4">
42-
<div className="bg-white dark:bg-gray-900 shadow transition sm:rounded-lg px-4 py-5 sm:p-6">
42+
<div className="bg-white dark:bg-gray-800 shadow transition sm:rounded-lg px-4 py-5 sm:p-6">
4343
<div className="grid lg:grid-cols-3 lg:gap-x-6 gap-y-4 lg:gap-y-0">
4444
<div className="col-span-2">
4545
<CalendarHeatmap

src/components/Dashboard/Announcements.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default function Announcements({
1111
<div className="flex overflow-x-auto sm:px-6 lg:px-8 py-4 grid lg:grid-cols-2 gap-8">
1212
{announcements.map(announcement => (
1313
<div
14-
className="bg-white dark:bg-gray-900 shadow transition sm:rounded-lg"
14+
className="bg-white dark:bg-gray-800 shadow transition sm:rounded-lg"
1515
key={announcement.id}
1616
>
1717
{/* hover:shadow-lg */}
@@ -20,7 +20,7 @@ export default function Announcements({
2020
<p className="text-sm leading-5 text-gray-500 dark:text-dark-med-emphasis">
2121
{announcement.date}
2222
</p>
23-
<h3 className="mt-2 text-xl leading-7 font-semibold text-gray-900 dark:text-dark-high-emphasis">
23+
<h3 className="mt-2 text-xl leading-7 font-semibold text-gray-800 dark:text-dark-high-emphasis">
2424
{announcement.title}
2525
</h3>
2626
<div className="mt-3 text-base leading-6 text-gray-500 dark:text-dark-med-emphasis -mb-4">

src/components/Dashboard/DailyStreak.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ const PhotoCard = ({ img, day, tomorrowMilliseconds, hiddenOnDesktop }) => {
4242
'max-w-[592px] mx-auto mb-8' + (hiddenOnDesktop ? ' lg:hidden' : '')
4343
}
4444
>
45-
<div className="bg-white dark:bg-gray-900 shadow sm:rounded-lg overflow-hidden flex flex-col">
45+
<div className="bg-white dark:bg-gray-800 shadow sm:rounded-lg overflow-hidden flex flex-col">
4646
<div className="px-4 pt-5 sm:px-6 sm:pt-6 pb-4">
47-
<h3 className="text-lg leading-6 font-medium text-gray-900 dark:text-dark-high-emphasis">
47+
<h3 className="text-lg leading-6 font-medium text-gray-800 dark:text-dark-high-emphasis">
4848
Day {day} Photo
4949
</h3>
5050
</div>
@@ -128,7 +128,7 @@ export default function DailyStreak({ streak }) {
128128
if (i == times.length) {
129129
return (
130130
<div className="mb-8" key={times.length}>
131-
<div className="bg-white dark:bg-gray-900 shadow sm:rounded-lg overflow-hidden flex flex-col">
131+
<div className="bg-white dark:bg-gray-800 shadow sm:rounded-lg overflow-hidden flex flex-col">
132132
<div className="px-4 py-5 sm:p-6">
133133
<div className="text-center">
134134
<h3 className="text-lg leading-6 font-medium text-gray-900 dark:text-dark-high-emphasis">
@@ -184,7 +184,7 @@ export default function DailyStreak({ streak }) {
184184
};
185185
return (
186186
<>
187-
<div className="bg-white dark:bg-gray-900 shadow sm:rounded-lg overflow-hidden lg:col-span-2">
187+
<div className="bg-white dark:bg-gray-800 shadow sm:rounded-lg overflow-hidden lg:col-span-2">
188188
<div className="px-4 py-5 sm:p-6">
189189
<div className="text-center">
190190
<h3 className="text-lg leading-6 font-medium text-gray-900 dark:text-dark-high-emphasis">

src/components/Dashboard/DashboardCard.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as React from 'react';
33
export default function DashboardCard(props) {
44
return (
55
<div
6-
className="bg-white shadow sm:rounded-lg dark:bg-gray-900"
6+
className="bg-white shadow sm:rounded-lg dark:bg-gray-800"
77
{...props}
88
/>
99
);

src/components/Dashboard/WelcomeBackBanner.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ export default function WelcomeBackBanner({
66
lastViewedModuleLabel,
77
}) {
88
return (
9-
<div className="bg-blue-700 dark:bg-blue-900 shadow hover:shadow-lg transition lg:rounded-lg w-full">
9+
<div className="bg-white dark:bg-gray-800 shadow lg:rounded-lg w-full">
1010
<Link
1111
className="px-4 py-6 sm:p-8 block sm:flex sm:items-center sm:justify-between"
1212
to={lastViewedModuleURL || '/general/using-this-guide'}
1313
>
1414
<div>
15-
<h3 className="text-xl sm:text-2xl leading-7 font-medium text-white dark:text-dark-high-emphasis">
15+
<h3 className="text-xl sm:text-2xl leading-7 font-medium text-black dark:text-dark-high-emphasis">
1616
{lastViewedModuleURL
1717
? 'Welcome Back!'
1818
: 'Welcome to the USACO Guide!'}
1919
</h3>
20-
<div className="mt-2 text-teal-200 dark:text-teal-300">
20+
<div className="mt-2 font-medium text-blue-600 dark:text-blue-300">
2121
<p>
2222
{lastViewedModuleURL
2323
? `Pick up where you left off. Your last viewed module was "${lastViewedModuleLabel}."`

src/components/TopNavigationBar/TopNavigationBar.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export default function TopNavigationBar({
4040
linkLogoToIndex = false,
4141
currentSection = null,
4242
hidePromoBar = false,
43+
redirectToDashboard = false,
4344
}) {
4445
const firebaseUser = useFirebaseUser();
4546
const signOut = useSignOutAction();
@@ -131,7 +132,6 @@ export default function TopNavigationBar({
131132
key: 'adv',
132133
},
133134
];
134-
135135
return (
136136
<>
137137
{!hidePromoBar && (
@@ -214,6 +214,7 @@ export default function TopNavigationBar({
214214
<div className="flex px-2 lg:px-0">
215215
<Link
216216
to={linkLogoToIndex ? '/' : '/dashboard'}
217+
state={{ redirect: redirectToDashboard }}
217218
className="flex-shrink-0 flex items-center"
218219
>
219220
<div className="block sm:hidden">

src/pages/dashboard.tsx

+16-18
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {
4040
} from '../utils/getProgressInfo';
4141

4242
export default function DashboardPage(props: PageProps) {
43-
const { modules, announcements, problems } = props.data as any;
43+
const { navigate, modules, announcements, problems } = props.data as any;
4444
const moduleIDToName = modules.edges.reduce((acc, cur) => {
4545
acc[cur.node.frontmatter.id] = cur.node.frontmatter.title;
4646
return acc;
@@ -168,7 +168,7 @@ export default function DashboardPage(props: PageProps) {
168168
<SEO title="Dashboard" />
169169

170170
<div className="min-h-screen bg-gray-100 dark:bg-dark-surface">
171-
<TopNavigationBar linkLogoToIndex={true} />
171+
<TopNavigationBar linkLogoToIndex={true} redirectToDashboard={false} />
172172

173173
<main className="pb-12">
174174
<div className="max-w-7xl mx-auto mb-4">
@@ -196,13 +196,21 @@ export default function DashboardPage(props: PageProps) {
196196
)}
197197
</div>
198198
</div>
199-
<div className="flex overflow-x-auto">
200-
<WelcomeBackBanner
201-
lastViewedModuleURL={lastViewedModuleURL}
202-
lastViewedModuleLabel={moduleIDToName[lastViewedModuleID]}
203-
/>
204-
</div>
199+
<WelcomeBackBanner
200+
lastViewedModuleURL={lastViewedModuleURL}
201+
lastViewedModuleLabel={moduleIDToName[lastViewedModuleID]}
202+
/>
203+
</div>
204+
</div>
205+
<header id="announcements">
206+
<div className="max-w-7xl mx-auto px-4 sm:px-8 lg:px-10">
207+
<h1 className="text-3xl font-bold leading-tight text-gray-900 dark:text-dark-high-emphasis">
208+
Announcements
209+
</h1>
205210
</div>
211+
</header>
212+
<div className="max-w-7xl mx-auto mb-8">
213+
<Announcements announcements={parsedAnnouncements} />
206214
</div>
207215
<div className="max-w-7xl mx-auto sm:px-6 lg:px-8 lg:grid lg:grid-cols-2 lg:gap-8">
208216
{activeProblems.length > 0 && (
@@ -216,16 +224,6 @@ export default function DashboardPage(props: PageProps) {
216224
</div>
217225
)}
218226
</div>
219-
<header id="announcements">
220-
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
221-
<h1 className="text-3xl font-bold leading-tight text-gray-900 dark:text-dark-high-emphasis">
222-
Announcements
223-
</h1>
224-
</div>
225-
</header>
226-
<div className="max-w-7xl mx-auto mb-8">
227-
<Announcements announcements={parsedAnnouncements} />
228-
</div>
229227
<header>
230228
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
231229
<h1 className="text-3xl font-bold leading-tight text-gray-900 dark:text-dark-high-emphasis">

src/pages/index.tsx

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useLocation } from '@gatsbyjs/reach-router';
12
import {
23
AcademicCapIcon,
34
ChartBarIcon,
@@ -10,7 +11,7 @@ import {
1011
UserGroupIcon,
1112
} from '@heroicons/react/outline';
1213
import classNames from 'classnames';
13-
import { Link } from 'gatsby';
14+
import { Link, navigate } from 'gatsby';
1415
import { StaticImage } from 'gatsby-plugin-image';
1516
import * as React from 'react';
1617
import { CPIProjectCard } from '../components/Index/CPIProjectCard';
@@ -28,6 +29,10 @@ import { GradientText } from '../components/elements/landing/GradientText';
2829
import { HighlightedText } from '../components/elements/landing/HighlightedText';
2930
import Layout from '../components/layout';
3031
import SEO from '../components/seo';
32+
import {
33+
useFirebaseUser,
34+
useIsUserDataLoaded,
35+
} from '../context/UserDataContext/UserDataContext';
3136

3237
const containerClasses = 'max-w-screen-xl mx-auto px-4 sm:px-6 lg:px-8';
3338
const headerClasses =
@@ -46,6 +51,24 @@ const linkTextStyles =
4651
'text-blue-600 dark:text-blue-300 transition hover:text-purple-600 dark:hover:text-purple-300';
4752

4853
export default function IndexPage(): JSX.Element {
54+
const firebaseUser = useFirebaseUser();
55+
const loading = useIsUserDataLoaded();
56+
const location = useLocation();
57+
React.useEffect(() => {
58+
// User will normally be redirected to the dashboard if the user is logged in, but if user clicks the icon in the top left corner while on the dashboard, they will not be redirected.
59+
try {
60+
if (firebaseUser && location.state.redirect) {
61+
/* Whether or not the user should be redirected to the dashboard is stored in location.state.redirect, but if the user opens a link straight
62+
to the landing page, location.state.redirect will be undefined, causing a typeerror, this try catch statements accounts for that */
63+
navigate('/dashboard');
64+
}
65+
} catch (e) {
66+
if (firebaseUser) {
67+
navigate('/dashboard');
68+
}
69+
}
70+
}, [firebaseUser, loading, location]);
71+
4972
return (
5073
<Layout>
5174
<SEO title={null} />

0 commit comments

Comments
 (0)