Skip to content

Commit

Permalink
Feature/improved downloads (#30)
Browse files Browse the repository at this point in the history
* First updated downloads page iteration

* Iteration 2 of new downloads

* Removed unused imports

* Added Octokit for typing and ease of use for getting releases

* added error handling and fallback

* Fix for possible infinite loader

* Fixed loader styling in light mode

* Update styles/components/Tabs.module.scss

Co-authored-by: André Oliveira <37463445+SpecialAro@users.noreply.github.com>

Co-authored-by: André Oliveira <37463445+SpecialAro@users.noreply.github.com>
  • Loading branch information
Dalgam and SpecialAro authored Jul 20, 2022
1 parent 53b9675 commit ce92b54
Show file tree
Hide file tree
Showing 12 changed files with 739 additions and 90 deletions.
15 changes: 14 additions & 1 deletion components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import styles from "styles/components/Button.module.scss";
type Props = {
children: ReactNode;
cta?: boolean;
cta2?: boolean;
size?: string;
square?: boolean;
onClick?: MouseEventHandler;
icon?: boolean;
["aria-label"]?: string;
Expand All @@ -12,7 +14,18 @@ type Props = {
};

const Button = (props: Props) => {
let className = props.cta ? styles.cta : styles.base;
let className = styles.base;

if (props.cta) {
className = styles.cta;
}

if (props.cta2) {
className = styles.ctaSecondary;
}
if (props.square) {
className += ` ${styles.square}`;
}

if (props.size) {
className += ` ${styles[props.size]}`;
Expand Down
15 changes: 15 additions & 0 deletions components/Loader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import styles from "styles/components/Loader.module.scss";

// source: https://loading.io/css/
const Loader = () => {
return (
<div className={styles["lds-ring"]}>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
);
};

export default Loader;
65 changes: 65 additions & 0 deletions components/PlatformDownloads.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { ReactNode } from "react";

import styles from "styles/components/PlatformDownloads.module.scss";
import Button from "./Button";
import ExternalLink from "./ExternalLink";
type Props = {
downloadTypes: Array<Type>;
grid?: boolean;
gridTemplate?: string;
gridTemplateArray?: Array<string>;
};
type Type = {
link?: Link;
title?: string;
multipleLinks?: Array<Link>;
};
export type Link = {
name?: string;
browser_download_url?: string;
};
const PlatformDownloads = (props: Props) => {
return (
<article className={styles.section}>
<div
className={styles.links + ` ${props.gridTemplate ? styles[props.gridTemplate] : ""}`}
style={props.grid ? { display: "grid" } : undefined}>
{props.downloadTypes.map((type, index) => {
let content: ReactNode;
if (type.link) {
content = (
<div className={styles.link}>
<ExternalLink href={type.link.browser_download_url ?? ""}>
<Button cta2 square>
{type.link.name}
</Button>
</ExternalLink>
</div>
);
}

if (type.multipleLinks) {
content = type.multipleLinks.map((altLink) => (
<div className={styles.link} key={altLink.name}>
<ExternalLink href={altLink.browser_download_url ?? ""}>
<Button cta2 square>
{altLink.name}
</Button>
</ExternalLink>
</div>
));
}

return (
<section key={type.title} style={{ gridArea: props.gridTemplateArray?.[index] ?? "0" }}>
<h3>{type.title}</h3>
<div className={styles.content}>{content}</div>
</section>
);
})}
</div>
</article>
);
};

export default PlatformDownloads;
47 changes: 47 additions & 0 deletions components/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { useState } from "react";
import styles from "styles/components/Tabs.module.scss";

type Props = {
value?: string;
options: Array<Option>;
onClick?: Function;
};
export type Option = {
title: string;
key: string;
};
const Tabs = (props: Props) => {
const [selectedOption, setSelectedOption] = useState<Option>();
const control = props.value ?? selectedOption?.key;
return (
<div className={styles.tabs}>
{props.options.map((tab: Option) => (
<Tab
option={tab}
key={tab.key}
selected={tab.key === control}
onClick={() => {
setSelectedOption(tab);
if (props.onClick) props.onClick(tab.key);
}}
/>
))}
</div>
);
};
type TabProps = {
selected: boolean;
option: Option;
onClick: Function;
};
const Tab = (props: TabProps) => {
return (
<button
className={styles.tab + ` ${props.selected ? styles.selected : ""}`}
onClick={() => props.onClick()}>
{props.option.title}
</button>
);
};

export default Tabs;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"dependencies": {
"@mdi/js": "^6.6.96",
"@mdi/react": "^1.6.0",
"@octokit/rest": "^19.0.3",
"next": "12.1.5",
"react": "18.0.0",
"react-dom": "18.0.0"
Expand Down
Loading

0 comments on commit ce92b54

Please sign in to comment.