Add a checkbox to include/exclude translations
This commit is contained in:
parent
f33fd3b49c
commit
1a2da9d4fc
@ -17,6 +17,7 @@ export interface Mod {
|
|||||||
description: string;
|
description: string;
|
||||||
thumbnail_link: string;
|
thumbnail_link: string;
|
||||||
game_id: number;
|
game_id: number;
|
||||||
|
is_translation: boolean;
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
created_at: string;
|
created_at: string;
|
||||||
last_update_at: string;
|
last_update_at: string;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
import React from "react";
|
import React, { useState } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
|
||||||
import styles from "../styles/CellModList.module.css";
|
import styles from "../styles/CellModList.module.css";
|
||||||
@ -19,15 +19,19 @@ type ModWithCounts = Mod & {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const CellModList: React.FC<Props> = ({ mods, counts }) => {
|
const CellModList: React.FC<Props> = ({ mods, counts }) => {
|
||||||
const modsWithCounts: ModWithCounts[] = mods.map((mod) => {
|
const [includeTranslations, setIncludeTranslations] = useState(true);
|
||||||
const modCounts = counts && counts[mod.nexus_mod_id];
|
|
||||||
return {
|
const modsWithCounts: ModWithCounts[] = mods
|
||||||
...mod,
|
.map((mod) => {
|
||||||
total_downloads: modCounts ? modCounts[0] : 0,
|
const modCounts = counts && counts[mod.nexus_mod_id];
|
||||||
unique_downloads: modCounts ? modCounts[1] : 0,
|
return {
|
||||||
views: modCounts ? modCounts[2] : 0,
|
...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");
|
let numberFmt = new Intl.NumberFormat("en-US");
|
||||||
|
|
||||||
@ -35,6 +39,14 @@ const CellModList: React.FC<Props> = ({ mods, counts }) => {
|
|||||||
mods && (
|
mods && (
|
||||||
<>
|
<>
|
||||||
<h2>Nexus Mods ({modsWithCounts.length})</h2>
|
<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"]}>
|
<ul className={styles["mod-list"]}>
|
||||||
{modsWithCounts
|
{modsWithCounts
|
||||||
.sort((a, b) => b.unique_downloads - a.unique_downloads)
|
.sort((a, b) => b.unique_downloads - a.unique_downloads)
|
||||||
|
@ -22,6 +22,7 @@ export interface Mod {
|
|||||||
description: string;
|
description: string;
|
||||||
thumbnail_link: string;
|
thumbnail_link: string;
|
||||||
game_id: number;
|
game_id: number;
|
||||||
|
is_translation: boolean;
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
created_at: string;
|
created_at: string;
|
||||||
last_update_at: string;
|
last_update_at: string;
|
||||||
@ -134,6 +135,7 @@ const ModData: React.FC<Props> = ({
|
|||||||
>
|
>
|
||||||
{data.category_name}
|
{data.category_name}
|
||||||
</a>
|
</a>
|
||||||
|
{data.is_translation && <strong> (translation)</strong>}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<strong>Author: </strong>
|
<strong>Author: </strong>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
import React from "react";
|
import React, { useState } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
|
||||||
import styles from "../styles/PluginModList.module.css";
|
import styles from "../styles/PluginModList.module.css";
|
||||||
@ -22,15 +22,19 @@ type ModWithCounts = Mod & {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const PluginModList: React.FC<Props> = ({ mods, files, counts }) => {
|
const PluginModList: React.FC<Props> = ({ mods, files, counts }) => {
|
||||||
const modsWithCounts: ModWithCounts[] = mods.map((mod) => {
|
const [includeTranslations, setIncludeTranslations] = useState(true);
|
||||||
const modCounts = counts && counts[mod.nexus_mod_id];
|
|
||||||
return {
|
const modsWithCounts: ModWithCounts[] = mods
|
||||||
...mod,
|
.map((mod) => {
|
||||||
total_downloads: modCounts ? modCounts[0] : 0,
|
const modCounts = counts && counts[mod.nexus_mod_id];
|
||||||
unique_downloads: modCounts ? modCounts[1] : 0,
|
return {
|
||||||
views: modCounts ? modCounts[2] : 0,
|
...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");
|
let numberFmt = new Intl.NumberFormat("en-US");
|
||||||
|
|
||||||
@ -38,6 +42,14 @@ const PluginModList: React.FC<Props> = ({ mods, files, counts }) => {
|
|||||||
mods && (
|
mods && (
|
||||||
<>
|
<>
|
||||||
<h2>Nexus Mods ({modsWithCounts.length})</h2>
|
<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"]}>
|
<ul className={styles["mod-list"]}>
|
||||||
{modsWithCounts
|
{modsWithCounts
|
||||||
.sort((a, b) => b.unique_downloads - a.unique_downloads)
|
.sort((a, b) => b.unique_downloads - a.unique_downloads)
|
||||||
|
@ -11,3 +11,11 @@
|
|||||||
.mod-title {
|
.mod-title {
|
||||||
margin-bottom: 8px;
|
margin-bottom: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.include-translations {
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.include-translations input {
|
||||||
|
margin-right: 8px;
|
||||||
|
}
|
||||||
|
@ -21,3 +21,11 @@
|
|||||||
.file-list li {
|
.file-list li {
|
||||||
margin-top: 8px;
|
margin-top: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.include-translations {
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.include-translations input {
|
||||||
|
margin-right: 8px;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user