Skip to content
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
64 changes: 14 additions & 50 deletions src/app/components/elements/PageTitle.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { ReactElement, useEffect, useRef } from "react";
import { UncontrolledTooltip, Button } from "reactstrap";
import { Link } from "react-router-dom";
import { UncontrolledTooltip } from "reactstrap";
import {
AUDIENCE_DISPLAY_FIELDS,
filterAudienceViewsByProperties,
Expand All @@ -17,15 +16,6 @@ import { Helmet } from "react-helmet";
import { Markup } from "./markup";
import { EditablePageTitle } from "./inputs/EditablePageTitle";

declare global {
interface Window {
followedAtLeastOneSoftLink?: boolean;
}

// eslint-disable-next-line no-var
var followedAtLeastOneSoftLink: boolean | undefined;
}

function AudienceViewer({ audienceViews }: { audienceViews: ViewingContext[] }) {
const userContext = useUserContext();
const viewsWithMyStage = audienceViews.filter((vc) => vc.stage === userContext.stage);
Expand Down Expand Up @@ -56,68 +46,33 @@ export interface PageTitleProps {
subTitle?: string;
disallowLaTeX?: boolean;
help?: ReactElement;
boosterVideoButton?: boolean;
className?: string;
audienceViews?: ViewingContext[];
onTitleEdit?: (newTitle: string) => void;
}

export const PageTitle = ({
currentPageTitle,
subTitle,
disallowLaTeX,
help,
boosterVideoButton,
className,
audienceViews,
onTitleEdit,
}: PageTitleProps) => {
const dispatch = useAppDispatch();
const openModal = useAppSelector((state: AppState) => Boolean(state?.activeModals?.length));
const user = useAppSelector((state: AppState) => state?.user);
const headerRef = useRef<HTMLHeadingElement>(null);

useEffect(() => {
dispatch(mainContentIdSlice.actions.set("main-heading"));
}, [dispatch]);

}, []);
useEffect(() => {
document.title = currentPageTitle + " — Isaac " + SITE_SUBJECT_TITLE;
const element = headerRef.current;
if (element && globalThis.followedAtLeastOneSoftLink && !openModal) {
if (element && (window as any).followedAtLeastOneSoftLink && !openModal) {
element.focus();
}
}, [currentPageTitle, openModal]);

// Extract nested ternary logic
const renderHelpOrBoosterButton = () => {
if (boosterVideoButton) {
const targetPath = user?.loggedIn
? "/pages/test_page_booster_recording"
: "/login?target=/pages/test_page_booster_recording";

return (
<Button tag={Link} to={targetPath} className="primary-button text-light align-self-center ml-sm-2">
Watch booster videos
</Button>
);
}

if (help) {
return (
<React.Fragment>
<div id="title-help" className="title-help">
Help
</div>
<UncontrolledTooltip target="#title-help" placement="bottom">
{help}
</UncontrolledTooltip>
</React.Fragment>
);
}

return null;
};
}, [currentPageTitle]);

return (
<h1 id="main-heading" tabIndex={-1} ref={headerRef} className={`h-title h-secondary d-sm-flex ${className ?? ""}`}>
Expand All @@ -133,7 +88,16 @@ export const PageTitle = ({
<meta property="og:title" content={currentPageTitle} />
</Helmet>
{audienceViews && <AudienceViewer audienceViews={audienceViews} />}
{renderHelpOrBoosterButton()}
{help && (
<React.Fragment>
<div id="title-help" className="title-help">
Help
</div>
<UncontrolledTooltip target="#title-help" placement="bottom">
{help}
</UncontrolledTooltip>
</React.Fragment>
)}
</h1>
);
};
Expand Down
10 changes: 6 additions & 4 deletions src/app/components/pages/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,16 @@ export const Events = withRouter(({ history, location }: RouteComponentProps) =>
dispatch(getEventMapData(startIndex, -1, typeFilter, statusFilter, stageFilter));
}, [dispatch, typeFilter, statusFilter, stageFilter]);

const pageHelp = <span>Follow the links below to find out more about our FREE events.</span>;

const metaDescriptionCS =
"A level and GCSE Computer Science live online training. Revision and extension workshops for students.";

return (
<>
<div>
<Container>
<TitleAndBreadcrumb currentPageTitle={"Events"} subTitle="Student Events" boosterVideoButton={true} />
<TitleAndBreadcrumb currentPageTitle={"Events"} subTitle="Student Events" help={pageHelp} />
<MetaDescription description={metaDescriptionCS} />
<div className="my-4">
{/* Filters */}
Expand All @@ -121,7 +123,7 @@ export const Events = withRouter(({ history, location }: RouteComponentProps) =>
query.show_reservations_only =
selectedFilter === EventStatusFilter["My event reservations"] ? true : undefined;
query.event_status = selectedFilter == EventStatusFilter["All events"] ? "all" : undefined;
history.push({ pathname: location.pathname, search: queryString.stringify(query as never) });
history.push({ pathname: location.pathname, search: queryString.stringify(query as any) });
}}
>
{/* Tutors are considered students w.r.t. events currently, so cannot see teacher-only events */}
Expand All @@ -148,7 +150,7 @@ export const Events = withRouter(({ history, location }: RouteComponentProps) =>
onChange={(e) => {
const selectedType = e.target.value as EventTypeFilter;
query.types = selectedType !== EventTypeFilter["All events"] ? selectedType : undefined;
history.push({ pathname: location.pathname, search: queryString.stringify(query as never) });
history.push({ pathname: location.pathname, search: queryString.stringify(query as any) });
}}
>
{Object.entries(EventTypeFilter).map(([typeLabel, typeValue]) => (
Expand All @@ -166,7 +168,7 @@ export const Events = withRouter(({ history, location }: RouteComponentProps) =>
const selectedStage = e.target.value as EventStageFilter;
query.show_stage_only =
selectedStage !== EventStageFilter["All stages"] ? selectedStage : undefined;
history.push({ pathname: location.pathname, search: queryString.stringify(query as never) });
history.push({ pathname: location.pathname, search: queryString.stringify(query as any) });
}}
>
{Object.entries(EventStageFilter)
Expand Down
Loading