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

[WIP] Random Course Picker #3676

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import classnames from 'classnames';
import { ElasticSearchResult } from 'types/vendor/elastic-search';
import { ModuleInformation } from 'types/modules';

import ModuleRandomPickerButton from 'views/modules/ModuleRandomPickerButton';
import ModuleFinderSidebar from 'views/modules/ModuleFinderSidebar';
import ModuleSearchBox from 'views/modules/ModuleSearchBox';
import ModuleFinderNoHits from 'views/errors/ModuleFinderNoHits';
Expand Down Expand Up @@ -65,6 +66,10 @@ const ModuleFinderContainer: React.FC = () => (

<ModuleSearchBox id="q" />

<ModuleRandomPickerButton tooltipTitle="Random module">
Discover a Random Module
</ModuleRandomPickerButton>

<div>
<HitsStats
component={({ hitsCount }: HitsStatsDisplayProps) => (
Expand Down
50 changes: 50 additions & 0 deletions website/src/views/modules/ModuleRandomPickerButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import * as React from 'react';
import classnames from 'classnames';
import { useHistory } from 'react-router-dom';

import { modulePage } from 'views/routes/paths';
import Tooltip from 'views/components/Tooltip';
import styles from './ModuleFinderPagerButton.scss';

type Props = {
readonly tooltipTitle?: string;
readonly disabled?: boolean;
readonly active?: boolean;
readonly children: React.ReactNode;
};

const ModuleRandomPickerButton: React.FC<Props> = ({
tooltipTitle,
disabled,
active,
children,
}) => {

const rng = Math.floor(Math.random() * 100);
const history = useHistory();
const button = (
<button
type="button"
className={classnames('btn', styles.pagerButton, {
[styles.active]: active,
})}
disabled={disabled}
onClick={() => history.push(modulePage('CS1010'))}
>
{children}
</button>
);
return (
<div>
{tooltipTitle ? (
<Tooltip content={tooltipTitle} delay={[800, 0]} touch="hold">
{button}
</Tooltip>
) : (
button
)}
</div>
);
};

export default ModuleRandomPickerButton;
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1