Add a checkbox to include/exclude translations

This commit is contained in:
Tyler Hallada 2022-03-16 00:37:08 -04:00
parent f33fd3b49c
commit 1a2da9d4fc
6 changed files with 63 additions and 20 deletions

View File

@ -17,6 +17,7 @@ export interface Mod {
description: string;
thumbnail_link: string;
game_id: number;
is_translation: boolean;
updated_at: string;
created_at: string;
last_update_at: string;

View File

@ -1,5 +1,5 @@
import { format } from "date-fns";
import React from "react";
import React, { useState } from "react";
import Link from "next/link";
import styles from "../styles/CellModList.module.css";
@ -19,15 +19,19 @@ type ModWithCounts = Mod & {
};
const CellModList: React.FC<Props> = ({ mods, counts }) => {
const modsWithCounts: ModWithCounts[] = mods.map((mod) => {
const modCounts = counts && counts[mod.nexus_mod_id];
return {
...mod,
total_downloads: modCounts ? modCounts[0] : 0,
unique_downloads: modCounts ? modCounts[1] : 0,
views: modCounts ? modCounts[2] : 0,
};
});
const [includeTranslations, setIncludeTranslations] = useState(true);
const modsWithCounts: ModWithCounts[] = mods
.map((mod) => {
const modCounts = counts && counts[mod.nexus_mod_id];
return {
...mod,
total_downloads: modCounts ? modCounts[0] : 0,
unique_downloads: modCounts ? modCounts[1] : 0,
views: modCounts ? modCounts[2] : 0,
};
})
.filter((mod) => includeTranslations || !mod.is_translation);
let numberFmt = new Intl.NumberFormat("en-US");
@ -35,6 +39,14 @@ const CellModList: React.FC<Props> = ({ mods, counts }) => {
mods && (
<>
<h2>Nexus Mods ({modsWithCounts.length})</h2>
<label className={styles["include-translations"]}>
<input
type="checkbox"
checked={includeTranslations}
onChange={() => setIncludeTranslations(!includeTranslations)}
/>
Include translations
</label>
<ul className={styles["mod-list"]}>
{modsWithCounts
.sort((a, b) => b.unique_downloads - a.unique_downloads)

View File

@ -22,6 +22,7 @@ export interface Mod {
description: string;
thumbnail_link: string;
game_id: number;
is_translation: boolean;
updated_at: string;
created_at: string;
last_update_at: string;
@ -134,6 +135,7 @@ const ModData: React.FC<Props> = ({
>
{data.category_name}
</a>
{data.is_translation && <strong>&nbsp;(translation)</strong>}
</div>
<div>
<strong>Author:&nbsp;</strong>

View File

@ -1,5 +1,5 @@
import { format } from "date-fns";
import React from "react";
import React, { useState } from "react";
import Link from "next/link";
import styles from "../styles/PluginModList.module.css";
@ -22,15 +22,19 @@ type ModWithCounts = Mod & {
};
const PluginModList: React.FC<Props> = ({ mods, files, counts }) => {
const modsWithCounts: ModWithCounts[] = mods.map((mod) => {
const modCounts = counts && counts[mod.nexus_mod_id];
return {
...mod,
total_downloads: modCounts ? modCounts[0] : 0,
unique_downloads: modCounts ? modCounts[1] : 0,
views: modCounts ? modCounts[2] : 0,
};
});
const [includeTranslations, setIncludeTranslations] = useState(true);
const modsWithCounts: ModWithCounts[] = mods
.map((mod) => {
const modCounts = counts && counts[mod.nexus_mod_id];
return {
...mod,
total_downloads: modCounts ? modCounts[0] : 0,
unique_downloads: modCounts ? modCounts[1] : 0,
views: modCounts ? modCounts[2] : 0,
};
})
.filter((mod) => includeTranslations || !mod.is_translation);
let numberFmt = new Intl.NumberFormat("en-US");
@ -38,6 +42,14 @@ const PluginModList: React.FC<Props> = ({ mods, files, counts }) => {
mods && (
<>
<h2>Nexus Mods ({modsWithCounts.length})</h2>
<label className={styles["include-translations"]}>
<input
type="checkbox"
checked={includeTranslations}
onChange={() => setIncludeTranslations(!includeTranslations)}
/>
Include translations
</label>
<ul className={styles["mod-list"]}>
{modsWithCounts
.sort((a, b) => b.unique_downloads - a.unique_downloads)

View File

@ -11,3 +11,11 @@
.mod-title {
margin-bottom: 8px;
}
.include-translations {
margin-bottom: 12px;
}
.include-translations input {
margin-right: 8px;
}

View File

@ -21,3 +21,11 @@
.file-list li {
margin-top: 8px;
}
.include-translations {
margin-bottom: 12px;
}
.include-translations input {
margin-right: 8px;
}