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

Reorganize Mod Data #752

Merged
merged 40 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
c8610c6
Ensure All Map Endpoints Return Techs
otobot1 Mar 30, 2024
8620dbd
begin implementing new columns
otobot1 Mar 30, 2024
0b1acd1
continue implementing new columns
otobot1 Mar 30, 2024
ae63010
fix regressions
otobot1 Mar 31, 2024
726b4df
get new columns working
otobot1 Mar 31, 2024
ff0848e
remove sorting for "secondary columns"
otobot1 Apr 1, 2024
1151a36
Merge branch 'main' into reorganize-mod-data
otobot1 Apr 1, 2024
fc0d025
Merge branch 'main' into reorganize-mod-data
otobot1 Apr 7, 2024
62aa08d
Merge branch 'main' into reorganize-mod-data
otobot1 Apr 8, 2024
93059f5
add underline to faq links
otobot1 Apr 8, 2024
845d0a4
Merge branch 'main' into reorganize-mod-data
otobot1 Apr 10, 2024
0edf491
limit string length in name and publisher columns
otobot1 Apr 10, 2024
45ac483
Update noRatingsFoundMessage.ts
otobot1 Apr 10, 2024
b1ad074
remove unused props and imports
otobot1 Apr 10, 2024
11b5560
convert default exports to named exports
otobot1 Apr 10, 2024
0122fa6
remove map queries from `Maps` component
otobot1 Apr 11, 2024
6172f75
add hardcoded difficulty names for rendering difficulty tabs before q…
otobot1 Apr 11, 2024
da8389f
remove the `ExpandedMod` component's header
otobot1 Apr 11, 2024
5e241be
refactor modDownloadButton to make generic LinkButton component
otobot1 Apr 11, 2024
2186022
replace "More Info" Link with LinkButton
otobot1 Apr 11, 2024
1b26a50
use `<a>` instead of `<Link>` for download button
otobot1 Apr 12, 2024
7cef5c6
improve cancelled fetch logs and disable excessive logs
otobot1 Apr 12, 2024
e4157d3
formatting
otobot1 Apr 14, 2024
e4c0aea
create and implement ModsTableTooltip component
otobot1 Apr 14, 2024
cd761df
add comment
otobot1 Apr 14, 2024
92e3906
switch to floating ModsTable tooltips instead of static
otobot1 Apr 14, 2024
ed83c1b
edit comments
otobot1 Apr 14, 2024
9218d6d
add tooltips to MapsTable
otobot1 Apr 15, 2024
89bb00b
edit comment
otobot1 Apr 15, 2024
6c6eed2
add custom render function to mapperName column
otobot1 Apr 15, 2024
3e1d69e
update const to refer to already existing const
otobot1 Apr 15, 2024
6f83a18
extract DifficultyTabs into its own component
otobot1 Apr 15, 2024
e50a52e
add link to "rate map" button
otobot1 Apr 15, 2024
57353ae
edit comments
otobot1 Apr 15, 2024
ebbcc5e
remove unneeded CSS
otobot1 Apr 22, 2024
a816e37
changes to render functions
otobot1 Apr 22, 2024
d65a96f
Add render function to map `length` column
otobot1 Apr 22, 2024
3c84135
move difficulty tabs back to `modsTable.tsx`
otobot1 Apr 22, 2024
d1ef11d
remove unnecessary if statements
otobot1 Apr 24, 2024
7c39047
adjust FC techs filtering logic
otobot1 Apr 24, 2024
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
99 changes: 99 additions & 0 deletions src/components/linkButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { useContext, forwardRef } from "react";
import Link from "next/link";
import { createStyles } from "@mantine/core";
import type { DifficultyColor } from "~/styles/difficultyColors";
import { colorsForDifficultyIndex } from "~/styles/modsColors";
import { currentDifficultyTabIndexContext } from "./mods/modsTable";




const useStyles = createStyles(
(
_theme,
{
colors,
}: {
colors: DifficultyColor;
}
) => {
return ({
button: {
backgroundColor: colors.primary.backgroundColor,
color: colors.primary.textColor,
/* left/right top/bottom */
padding: "2px 10px",
border: "none",
borderRadius: "8px",
width: "fit-content",
otobot1 marked this conversation as resolved.
Show resolved Hide resolved
"&:hover": {
backgroundColor: colors.primaryHover.backgroundColor,
color: colors.primaryHover.textColor,
}
},
});
}
);




type LinkButtonProps = {
children: React.ReactNode;
href: string;
onMouseEnter?: () => void;
onMouseLeave?: () => void;
linkWrapper?: boolean;
};




export const LinkButton = forwardRef<
HTMLAnchorElement,
LinkButtonProps
>(
(
{
children,
href,
onMouseEnter,
onMouseLeave,
linkWrapper = true,
},
ref,
) => {
const currentTabIndex = useContext(currentDifficultyTabIndexContext);

const colors = colorsForDifficultyIndex(currentTabIndex ?? 0); // default to beginner colors if no context is provided. null would give the highest valid difficulty's color.

const { classes } = useStyles({ colors });


return (
linkWrapper ? (
<Link
href={href}
ref={ref}
type="button"
className={classes.button}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
>
{children}
</Link>
) : (
<a
href={href}
ref={ref}
type="button"
className={classes.button}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
>
{children}
</a>
)
);
}
);
195 changes: 195 additions & 0 deletions src/components/mods/difficultyTabs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
import { useEffect, useState, type SetStateAction, type RefObject } from "react";
import { createPortal } from "react-dom";
import { createStyles } from "@mantine/core";
import { canonicalDifficultyNames } from "~/styles/difficultyColors";
import { difficultyColors, type DifficultyColor } from "~/styles/difficultyColors";
import { blackBackgroundColor } from "~/styles/layoutColors";




const useStyles = createStyles(
(
_theme,
{ colors }: { colors: DifficultyColor; },
) => {
return ({
tabContainer: {
position: "sticky",
top: "0",
zIndex: 2,
display: "flex",
justifyContent: "end",
padding: "0 15px",
backgroundColor: blackBackgroundColor,
},
tab: {
padding: "1px 20px",
display: "inline-block",
borderTopLeftRadius: "5px",
borderTopRightRadius: "5px",
borderTop: "2px",
borderTopStyle: "solid",
borderTopColor: "transparent",
fontSize: "medium",
cursor: "pointer",
fontWeight: "bold",
},
activeTab: {
borderTopColor: `${colors.primaryHover.backgroundColor}`, // add top border to active tab so it's easier to see which tab is active (the contrast ratio between the difficulty colors is not sufficient on its own)
},
// color the difficulty tabs
beginner: {
backgroundColor: difficultyColors.beginner.primary.backgroundColor,
color: difficultyColors.beginner.primary.textColor,
":hover": {
backgroundColor: difficultyColors.beginner.primaryHover.backgroundColor,
color: difficultyColors.beginner.primaryHover.textColor,
},
},
intermediate: {
backgroundColor: difficultyColors.intermediate.primary.backgroundColor,
color: difficultyColors.intermediate.primary.textColor,
":hover": {
backgroundColor: difficultyColors.intermediate.primaryHover.backgroundColor,
color: difficultyColors.intermediate.primaryHover.textColor,
},
},
advanced: {
backgroundColor: difficultyColors.advanced.primary.backgroundColor,
color: difficultyColors.advanced.primary.textColor,
":hover": {
backgroundColor: difficultyColors.advanced.primaryHover.backgroundColor,
color: difficultyColors.advanced.primaryHover.textColor,
},
},
expert: {
backgroundColor: difficultyColors.expert.primary.backgroundColor,
color: difficultyColors.expert.primary.textColor,
":hover": {
backgroundColor: difficultyColors.expert.primaryHover.backgroundColor,
color: difficultyColors.expert.primaryHover.textColor,
},
},
grandmaster: {
backgroundColor: difficultyColors.grandmaster.primary.backgroundColor,
color: difficultyColors.grandmaster.primary.textColor,
":hover": {
backgroundColor: difficultyColors.grandmaster.primaryHover.backgroundColor,
color: difficultyColors.grandmaster.primaryHover.textColor,
},
},
astral: {
backgroundColor: difficultyColors.astral.primary.backgroundColor,
color: difficultyColors.astral.primary.textColor,
":hover": {
backgroundColor: difficultyColors.astral.primaryHover.backgroundColor,
color: difficultyColors.astral.primaryHover.textColor,
},
},
celestial: {
backgroundColor: difficultyColors.celestial.primary.backgroundColor,
color: difficultyColors.celestial.primary.textColor,
":hover": {
backgroundColor: difficultyColors.celestial.primaryHover.backgroundColor,
color: difficultyColors.celestial.primaryHover.textColor,
},
},
});
}
);




type CurrentTabIndex = number | null;

type DifficultyTabsProps = {
colors: DifficultyColor;
tableBodyRef: RefObject<HTMLTableSectionElement>;
parentDifficultyNames: string[];
currentTabIndex: CurrentTabIndex;
setCurrentTabIndex: (value: SetStateAction<CurrentTabIndex>) => void;
};




export const DifficultyTabs = ({
colors,
tableBodyRef,
parentDifficultyNames,
currentTabIndex,
setCurrentTabIndex,
}: DifficultyTabsProps) => {
const { cx, classes } = useStyles({ colors });


const tabColors: string[] = Array(canonicalDifficultyNames.length);

Object.entries(classes).forEach(
([key, value]) => {
for (let index = 0; index < canonicalDifficultyNames.length; index++) {
if (key === canonicalDifficultyNames[index]) {
tabColors[index] = value;
break;
}
}
}
);


// We want to render the tab container inside the scroll area of the datatable, so we use ref and portal.
const [tabContainer, setTabContainer] = useState<HTMLDivElement | null>(null);

useEffect(() => {
const tabsParent = tableBodyRef.current?.parentElement?.parentElement;

if (!tabsParent) {
throw "Couldn't find tabsParent.";
}


const tabContainer = document.createElement("div");

tabContainer.className = classes.tabContainer;

tabsParent.prepend(tabContainer);

setTabContainer(tabContainer);


return () => {
tabsParent.removeChild(tabContainer);

setTabContainer(null);
};
}, [classes.tabContainer]);


return (
tabContainer !== null && (
createPortal(
[...parentDifficultyNames].reverse().map(
(name, index) =>
<span
key={name}
className={
cx(
classes.tab,
tabColors[parentDifficultyNames.length - 1 - index],
{ [classes.activeTab]: parentDifficultyNames.length - 1 - index === currentTabIndex }
)
}
onClick={() => {
setCurrentTabIndex(parentDifficultyNames.length - 1 - index);
}}
>
{name}
</span>
),
tabContainer
)
)
);
};
Loading
Loading