From 61131ca11add7a2345dceba5983023a55fc24be6 Mon Sep 17 00:00:00 2001 From: DarkIntaqt <61588850+DarkIntaqt@users.noreply.github.com> Date: Sun, 6 Oct 2024 23:02:53 +0200 Subject: [PATCH] moved to 2024300 --- src/css/user.module.css | 2 +- src/func/generateChallengeBlock.js | 102 +- src/func/showChallengePath.js | 257 ++-- src/module/Challenge.js | 1455 ++++++++++-------- src/module/Challenges.js | 11 +- src/module/events/Event.js | 175 ++- src/module/user/UserChallenges.js | 953 +++++++----- src/module/user/orderChallenges.js | 6 +- src/module/user/statsCalculateTotalPoints.js | 54 +- 9 files changed, 1693 insertions(+), 1322 deletions(-) diff --git a/src/css/user.module.css b/src/css/user.module.css index 3ea8456..aed1fa6 100644 --- a/src/css/user.module.css +++ b/src/css/user.module.css @@ -272,7 +272,7 @@ img.mclogo { .profile.c:not(.cid0):not(.cid1):not(.cid2):not(.cid3):not(.cid4):not(.cid5):not(.cid2022000):not(.cid2023000):not( .cid2024100 - ):not(.cid2024200)::before { + ):not(.cid2024200):not(.cid2024300)::before { height: 80px; width: 80px; margin: 30px; diff --git a/src/func/generateChallengeBlock.js b/src/func/generateChallengeBlock.js index e115b51..993223a 100644 --- a/src/func/generateChallengeBlock.js +++ b/src/func/generateChallengeBlock.js @@ -1,56 +1,62 @@ -import { Fragment } from "react" -import { LazyLoadImage } from "react-lazy-load-image-component" -import aboutChallenge from "../css/aboutChallenge.module.css" -import goTo from "./goTo" -import capstone from "../img/capstone.svg" -import { checkExists } from "./arrayManipulationFunctions.js" - +import { Fragment } from "react"; +import { LazyLoadImage } from "react-lazy-load-image-component"; +import aboutChallenge from "../css/aboutChallenge.module.css"; +import goTo from "./goTo"; +import capstone from "../img/capstone.svg"; +import { checkExists } from "./arrayManipulationFunctions.js"; /** - * Function to generate a react object which shows a challenge - * @param {object} content - * @param {boolean} genLine - * @returns {object} - React object containing the name and the image of a challenge - */ -export default function generateObject(content, genLine = true, challengeId = -1) { - - // Additional stylesheet might be needed, as the challenge will be colored blue if it is the current one - let additionalStylesheet = "" - - if (content.id === challengeId) { - - additionalStylesheet = " " + aboutChallenge.this - - } - - let imageurl = "https://lolcdn.darkintaqt.com/cdn/np-token" + content.id - if (content.id < 10 || content.id === 2022000 || content.id === 2023000 || content.id === 2024100 || content.id === 2024200) { - if (content.id !== 0) { - imageurl = "https://cdn.darkintaqt.com/lol/static/challenges/" + content.translation.name.toLowerCase().replace(" ", "") + ".svg" - } + * Function to generate a react object which shows a challenge + * @param {object} content + * @param {boolean} genLine + * @returns {object} - React object containing the name and the image of a challenge + */ +export default function generateObject( + content, + genLine = true, + challengeId = -1 +) { + // Additional stylesheet might be needed, as the challenge will be colored blue if it is the current one + let additionalStylesheet = ""; + + if (content.id === challengeId) { + additionalStylesheet = " " + aboutChallenge.this; + } + + let imageurl = "https://lolcdn.darkintaqt.com/cdn/np-token" + content.id; + if ( + content.id < 10 || + content.id === 2022000 || + content.id === 2023000 || + content.id === 2024100 || + content.id === 2024200 || + content.id === 2024300 + ) { + if (content.id !== 0) { + imageurl = + "https://cdn.darkintaqt.com/lol/static/challenges/" + + content.translation.name.toLowerCase().replace(" ", "") + + ".svg"; } + } - return - - {genLine ? -
- : null} - - - - {checkExists(content.tags.isCapstone) - ? : - null} - - - -

- - {content.translation.name} + return ( + + {genLine ?

: null} -

+
+ {checkExists(content.tags.isCapstone) ? ( + + ) : null} - + +

{content.translation.name}

+
-} \ No newline at end of file + ); +} diff --git a/src/func/showChallengePath.js b/src/func/showChallengePath.js index b17e9fc..6394820 100644 --- a/src/func/showChallengePath.js +++ b/src/func/showChallengePath.js @@ -1,149 +1,164 @@ import getChallenge from "./getChallenge"; import { LazyLoadImage } from "react-lazy-load-image-component"; -import aboutChallenge from "../css/aboutChallenge.module.css" +import aboutChallenge from "../css/aboutChallenge.module.css"; import { Fragment } from "react"; -import capstone from "../img/capstone.svg" +import capstone from "../img/capstone.svg"; import goTo from "../func/goTo.js"; -import generateObject from "./generateChallengeBlock" +import generateObject from "./generateChallengeBlock"; import { checkExists } from "./arrayManipulationFunctions.js"; export default function showChallengePath(challenges, challenge) { - // getChallenge - window.JSONPREQUEST = challenges; - - - // define parentChallenge and categoryChallenge - let parent = getChallenge(challenge.parent) - let category = getChallenge(challenge.parentCategory) - - - // set category to parent if they are the same or parent is a key-capstone - if (category.id === 0 && parent.id !== 0 && (parent.id < 10 || parent.id === 2022000 || parent.id === 2023000 || parent.id === 2024100 || content.id === 2024200)) { - category = parent - } - - - let capstonetext = - This challenge is a capstone. That means, that this challenge is like a category and has multiple challenges grouped under its name. + // getChallenge + window.JSONPREQUEST = challenges; + + // define parentChallenge and categoryChallenge + let parent = getChallenge(challenge.parent); + let category = getChallenge(challenge.parentCategory); + + // set category to parent if they are the same or parent is a key-capstone + if ( + category.id === 0 && + parent.id !== 0 && + (parent.id < 10 || + parent.id === 2022000 || + parent.id === 2023000 || + parent.id === 2024100 || + parent.id === 2024200 || + parent.id === 2024300) + ) { + category = parent; + } + + let capstonetext = ( + + This challenge is a capstone. That means, that this challenge is like a + category and has multiple challenges grouped under its name. + ); + // if parent is also the category, they are less options to display + if (parent.id === category.id) { + if (parent.parent === challenge.parent) { + // returns only the challenges, as it is the key-capstone + return ( +
+

Capstones

- // if parent is also the category, they are less options to display - if (parent.id === category.id) { - - if (parent.parent === challenge.parent) { - - // returns only the challenges, as it is the key-capstone - return
- -

Capstones

- - {!checkExists(challenge.tags.isCapstone) - ? -
- - : null} - - {generateObject(challenge, false, challenge.id)} - - {checkExists(challenge.tags.isCapstone) - ? -
- -

- {capstonetext} -

-
- : null} - -
- - } - - // else return challenge and parent (key-capstone) - return
- -

Capstones

- - - - {checkExists(category.tags.isCapstone) - ? - : null} + {!checkExists(challenge.tags.isCapstone) ? ( +
+ ) : null} - + {generateObject(challenge, false, challenge.id)} -

- {category.translation.name} -

-
+ {checkExists(challenge.tags.isCapstone) ? ( + +
- {generateObject(challenge, true, challenge.id)} - - {checkExists(challenge.tags.isCapstone) - ? -
- -

- {capstonetext} -

-
- : null} +

{capstonetext}

+
+ ) : null}
+ ); } + // else return challenge and parent (key-capstone) + return ( +
+

Capstones

- // if a challenge has more than 2 parent-challenges, this array will be filled - let moreChallenges = []; + + {checkExists(category.tags.isCapstone) ? ( + + ) : null} + + + +

{category.translation.name}

+
+ {generateObject(challenge, true, challenge.id)} - // if the challenges parent is not a key-capstone, loop until it is found - if (parent.parent > 10) { + {checkExists(challenge.tags.isCapstone) ? ( + +
- let tries = 0; +

{capstonetext}

+
+ ) : null} +
+ ); + } - let temporaryChallenge = parent + // if a challenge has more than 2 parent-challenges, this array will be filled + let moreChallenges = []; - // max 10 tries - while (temporaryChallenge.parent > 10 || tries > 5) { + // if the challenges parent is not a key-capstone, loop until it is found + if (parent.parent > 10) { + let tries = 0; - // set temp to the parent of the temp before - temporaryChallenge = getChallenge(temporaryChallenge.parent); + let temporaryChallenge = parent; - //console.log(temporaryChallenge); // debug - moreChallenges.push(generateObject(getChallenge(temporaryChallenge.id))) + // max 10 tries + while (temporaryChallenge.parent > 10 || tries > 5) { + // set temp to the parent of the temp before + temporaryChallenge = getChallenge(temporaryChallenge.parent); - tries++; + //console.log(temporaryChallenge); // debug + moreChallenges.push(generateObject(getChallenge(temporaryChallenge.id))); - } + tries++; } - - - // Returns the right section of the challenge page, containing all the paths the current challenge has - return
-

Capstones

- - - {checkExists(category.tags.isCapstone) ? - - : null} - - - -

- {category.translation.name} -

-
- - {moreChallenges} - - {generateObject(parent)} - - {generateObject(challenge, true, challenge.id)} - - {checkExists(challenge.tags.isCapstone) ? -

{capstonetext}

- : null} + } + + // Returns the right section of the challenge page, containing all the paths the current challenge has + return ( +
+

Capstones

+ + {checkExists(category.tags.isCapstone) ? ( + + ) : null} + + + +

{category.translation.name}

+
+ + {moreChallenges} + + {generateObject(parent)} + + {generateObject(challenge, true, challenge.id)} + + {checkExists(challenge.tags.isCapstone) ? ( +

{capstonetext}

+ ) : null}
- -} \ No newline at end of file + ); +} diff --git a/src/module/Challenge.js b/src/module/Challenge.js index 5828334..dce32be 100644 --- a/src/module/Challenge.js +++ b/src/module/Challenge.js @@ -1,15 +1,15 @@ import { Component, Fragment } from "react"; -import Error from "./Error" -import get from "../func/get" -import { getCache } from "../func/getCheckCache" -import css from "../css/user.module.css" -import { serverToHumanReadable, serverToMachineReadable } from "../func/server" -import Timestamp from "react-timestamps" -import { beautifyNum } from "../func/beautify.js" +import Error from "./Error"; +import get from "../func/get"; +import { getCache } from "../func/getCheckCache"; +import css from "../css/user.module.css"; +import { serverToHumanReadable, serverToMachineReadable } from "../func/server"; +import Timestamp from "react-timestamps"; +import { beautifyNum } from "../func/beautify.js"; import { intToTier } from "../func/tierFunctions"; import { LazyLoadImage } from "react-lazy-load-image-component"; import goTo from "../func/goTo.js"; -import start from "../css/start.module.css" +import start from "../css/start.module.css"; // import showChallengePath from "../func/showChallengePath.js" // import ShowChildChallenges from "../func/getChildChallenges"; import { checkExists } from "../func/arrayManipulationFunctions.js"; @@ -18,8 +18,8 @@ import config from "../config"; import { capitalize, strtolower, strtoupper } from "../func/stringManipulation"; import Wrapper from "./Wrapper"; //import VipBadge from "./VipBadge"; -import VipBadge from "./VipBadge" -import Ad from "./Ad" +import VipBadge from "./VipBadge"; +import Ad from "./Ad"; import { withTranslation } from "react-i18next"; import { Chart } from "chart.js/auto"; @@ -27,640 +27,863 @@ import { Chart } from "chart.js/auto"; //import excss from "../css/aboutChallenge.module.css" class Challenge extends Component { - constructor(props) { - super(props) - this.params = this.props.params - this.regions = config.regions - this.tiers = config.tiers - - let tempRegion = props.query.toLowerCase(); - if (!tempRegion) { - tempRegion = "world" - } - - this.challenge = "null" - - this.load = this.load.bind(this) - this.error = this.error.bind(this) - - this.loadChallenge = this.loadChallenge.bind(this) - - this.changeFilter = this.changeFilter.bind(this) - this.showChallenge = this.showChallenge.bind(this) - - let challengePlaceholder = { - text: false, - title: [], - icon: 1, - timestamp: Date.now() / 1000, - challenge: { - id: 0, - parent: 0, - translation: { - name: "Loading", - description: "Loading" - } - }, - } - - const tempChallenge = getCache(`https://challenges.darkintaqt.com/api/v5/c/?id=${this.params.id}`) - - if (tempChallenge !== false) { - this.challenge = tempChallenge - challengePlaceholder = tempChallenge - document.title = "'" + tempChallenge.challenge.translation.name + "' Challenge Overview and Leaderboard" - } - - - this.state = { - totalLength: 250, - message: -1, - filter: tempRegion, - challenge: challengePlaceholder, - translation: props.t - } - + constructor(props) { + super(props); + this.params = this.props.params; + this.regions = config.regions; + this.tiers = config.tiers; + + let tempRegion = props.query.toLowerCase(); + if (!tempRegion) { + tempRegion = "world"; } - - error() { - this.setState({ - message: , - }) + this.challenge = "null"; + + this.load = this.load.bind(this); + this.error = this.error.bind(this); + + this.loadChallenge = this.loadChallenge.bind(this); + + this.changeFilter = this.changeFilter.bind(this); + this.showChallenge = this.showChallenge.bind(this); + + let challengePlaceholder = { + text: false, + title: [], + icon: 1, + timestamp: Date.now() / 1000, + challenge: { + id: 0, + parent: 0, + translation: { + name: "Loading", + description: "Loading", + }, + }, + }; + + const tempChallenge = getCache( + `https://challenges.darkintaqt.com/api/v5/c/?id=${this.params.id}` + ); + + if (tempChallenge !== false) { + this.challenge = tempChallenge; + challengePlaceholder = tempChallenge; + document.title = + "'" + + tempChallenge.challenge.translation.name + + "' Challenge Overview and Leaderboard"; } - showChallenge(r) { - document.title = "'" + r.challenge.translation.name + "' Challenge Overview, Thresholds and Leaderboards" - this.setState({ challenge: r }) + this.state = { + totalLength: 250, + message: -1, + filter: tempRegion, + challenge: challengePlaceholder, + translation: props.t, + }; + } + + error() { + this.setState({ + message: , + }); + } + + showChallenge(r) { + document.title = + "'" + + r.challenge.translation.name + + "' Challenge Overview, Thresholds and Leaderboards"; + this.setState({ challenge: r }); + } + + componentDidUpdate() { + if (this.props.params !== this.params) { + this.params = this.props; + //window.location.reload() + const props = this.props; + + this.params = this.props.params; + this.regions = config.regions; + this.tiers = config.tiers; + + let tempRegion = props.query.toLowerCase(); + if (!this.regions.includes(tempRegion)) { + tempRegion = "world"; + } + + this.challenge = "null"; + + this.load = this.load.bind(this); + this.error = this.error.bind(this); + + this.loadChallenge = this.loadChallenge.bind(this); + + this.changeFilter = this.changeFilter.bind(this); + this.showChallenge = this.showChallenge.bind(this); + + let challengePlaceholder = { + text: false, + title: [], + icon: 1, + timestamp: Date.now() / 1000, + challenge: { + id: 0, + parent: 0, + translation: { + name: "Loading", + description: "Loading", + }, + }, + }; + + const tempChallenge = getCache( + `https://challenges.darkintaqt.com/api/v5/c/?id=${this.params.id}` + ); + + if (tempChallenge !== false) { + this.challenge = tempChallenge; + challengePlaceholder = tempChallenge; + document.title = + "'" + + tempChallenge.challenge.translation.name + + "' Challenge Overview and Leaderboard"; + } + + this.setState({ + totalLength: 250, + message: -1, + filter: tempRegion, + challenge: challengePlaceholder, + translation: props.t, + }); + + if (this.challenge === "null") { + this.load(); + } + } else { + this.chart(); } - - componentDidUpdate() { - if (this.props.params !== this.params) { - this.params = this.props; - //window.location.reload() - const props = this.props; - - this.params = this.props.params - this.regions = config.regions - this.tiers = config.tiers - - let tempRegion = props.query.toLowerCase(); - if (!this.regions.includes(tempRegion)) { - tempRegion = "world" - } - - this.challenge = "null" - - this.load = this.load.bind(this) - this.error = this.error.bind(this) - - this.loadChallenge = this.loadChallenge.bind(this) - - this.changeFilter = this.changeFilter.bind(this) - this.showChallenge = this.showChallenge.bind(this) - - let challengePlaceholder = { - text: false, - title: [], - icon: 1, - timestamp: Date.now() / 1000, - challenge: { - id: 0, - parent: 0, - translation: { - name: "Loading", - description: "Loading" - } - }, - } - - const tempChallenge = getCache(`https://challenges.darkintaqt.com/api/v5/c/?id=${this.params.id}`) - - if (tempChallenge !== false) { - this.challenge = tempChallenge - challengePlaceholder = tempChallenge - document.title = "'" + tempChallenge.challenge.translation.name + "' Challenge Overview and Leaderboard" - } - - - this.setState({ - totalLength: 250, - message: -1, - filter: tempRegion, - challenge: challengePlaceholder, - translation: props.t - }); - - if (this.challenge === "null") { - this.load(); - } + } + + chart() { + try { + let chartStatus = Chart.getChart("average"); + if (checkExists(chartStatus)) { + chartStatus.destroy(); + } + + const label = (tootltipItems) => { + if (tootltipItems[0].label === "Today") { + return "Todays data might be inaccurate, as it is calculated live. "; } - else { - this.chart() - } - } - - chart() { - try { - let chartStatus = Chart.getChart("average"); - if (checkExists(chartStatus)) { - chartStatus.destroy(); - } - const label = (tootltipItems) => { - - if (tootltipItems[0].label === "Today") { - - return "Todays data might be inaccurate, as it is calculated live. " - - } - - return ""; - - } - - const data = { - labels: [ - "6 days ago", - "5 days ago", - "4 days ago", - "3 days ago", - "2 days ago", - "Yesterday", - "Today" - ], - datasets: [{ - label: 'Ø points per game', - backgroundColor: getComputedStyle(document.documentElement).getPropertyValue('--selected'), - borderColor: getComputedStyle(document.documentElement).getPropertyValue('--selected'), - data: this.state.challenge.progress - }] - }; - - const chartConfig = { - type: 'line', - data: data, - options: { - animation: false, - radius: 7, - plugins: { - tooltip: { - callbacks: { - footer: label, - } - }, - legend: { - display: false - } - }, - scales: { - x: { - ticks: { - display: false, - }, - grid: { - display: false, - drawBorder: false, - color: getComputedStyle(document.documentElement).getPropertyValue('--dark3'), - } - }, - y: { - ticks: { - display: false, - }, - grid: { - display: false, - drawBorder: false, - color: getComputedStyle(document.documentElement).getPropertyValue('--dark3'), - }, - } - } - } - }; - - // render chart - new Chart( - document.getElementById("average"), - chartConfig - ); - } catch (e) { - console.warn(e); - } + return ""; + }; + + const data = { + labels: [ + "6 days ago", + "5 days ago", + "4 days ago", + "3 days ago", + "2 days ago", + "Yesterday", + "Today", + ], + datasets: [ + { + label: "Ø points per game", + backgroundColor: getComputedStyle( + document.documentElement + ).getPropertyValue("--selected"), + borderColor: getComputedStyle( + document.documentElement + ).getPropertyValue("--selected"), + data: this.state.challenge.progress, + }, + ], + }; + + const chartConfig = { + type: "line", + data: data, + options: { + animation: false, + radius: 7, + plugins: { + tooltip: { + callbacks: { + footer: label, + }, + }, + legend: { + display: false, + }, + }, + scales: { + x: { + ticks: { + display: false, + }, + grid: { + display: false, + drawBorder: false, + color: getComputedStyle( + document.documentElement + ).getPropertyValue("--dark3"), + }, + }, + y: { + ticks: { + display: false, + }, + grid: { + display: false, + drawBorder: false, + color: getComputedStyle( + document.documentElement + ).getPropertyValue("--dark3"), + }, + }, + }, + }, + }; + + // render chart + new Chart(document.getElementById("average"), chartConfig); + } catch (e) { + console.warn(e); } + } - componentDidMount() { - if (this.challenge === "null") { - this.load(); - } - // else { - // this.chart(); - // } + componentDidMount() { + if (this.challenge === "null") { + this.load(); } - - - load() { - document.title = "Loading..." - get(`https://challenges.darkintaqt.com/api/v5/c/?id=${this.params.id}`, this.loadChallenge, this.error); + // else { + // this.chart(); + // } + } + + load() { + document.title = "Loading..."; + get( + `https://challenges.darkintaqt.com/api/v5/c/?id=${this.params.id}`, + this.loadChallenge, + this.error + ); + } + + loadChallenge(challenge) { + this.challenge = challenge; + if (this.challenge !== "null") { + this.showChallenge(this.challenge); } - - loadChallenge(challenge) { - this.challenge = challenge; - if (this.challenge !== "null") { - this.showChallenge(this.challenge) + } + + changeFilter(e) { + var isRightMB = false; + var isMB2 = false; + e.preventDefault(); + + if ("which" in e) + // Gecko (Firefox), WebKit (Safari/Chrome) & Opera + isRightMB = e.which === 3; + isMB2 = e.which === 2; + + let filter = "world"; + + if (e.target.id === "world") { + let url = new URL(window.location); + url.search = ""; + window.history.replaceState({}, "", url); + } else { + filter = e.target.id; + + if (isRightMB || e.ctrlKey || e.altKey) { + filter = ""; + for (let i = 0; i < this.regions.length; i++) { + const region = this.regions[i]; + + if (region !== e.target.id) { + filter += region + ";"; + } } - } - - - changeFilter(e) { - - var isRightMB = false; - var isMB2 = false; - e.preventDefault(); - - if ("which" in e) // Gecko (Firefox), WebKit (Safari/Chrome) & Opera - isRightMB = e.which === 3; - isMB2 = e.which === 2; - - - let filter = "world"; - - if (e.target.id === "world") { - let url = new URL(window.location) - url.search = ""; - window.history.replaceState({}, "", url) - } else { - - filter = e.target.id; - - if (isRightMB || e.ctrlKey || e.altKey) { - - filter = ""; - for (let i = 0; i < this.regions.length; i++) { - const region = this.regions[i]; - - if (region !== e.target.id) { - filter += region + ";" - } - - } - + } else if (e.shiftKey || isMB2) { + const tempFilter = this.state.filter.split(";"); + if (tempFilter.includes(filter)) { + if (tempFilter.length > 1) { + var index = tempFilter.indexOf(filter); + if (index !== -1) { + tempFilter.splice(index, 1); } - else if (e.shiftKey || isMB2) { - - const tempFilter = this.state.filter.split(";") - if (tempFilter.includes(filter)) { - - if (tempFilter.length > 1) { - var index = tempFilter.indexOf(filter); - if (index !== -1) { - tempFilter.splice(index, 1); - } - - filter = tempFilter.join(";"); - } else { - filter = this.state.filter; - } - - } else { - - console.log(tempFilter) - - if (tempFilter[0] !== "world") { - - filter = this.state.filter + ";" + filter - - } - - } - } + filter = tempFilter.join(";"); + } else { + filter = this.state.filter; + } + } else { + console.log(tempFilter); - window.history.replaceState({}, "", "?region=" + filter) + if (tempFilter[0] !== "world") { + filter = this.state.filter + ";" + filter; + } } - this.setState({ filter: filter }); - } - - render() { - try { - const t = this.state.translation - - if (document.location.pathname.slice(-1) === "/") { - return - } + } - const challenge = JSON.parse(JSON.stringify(this.state.challenge)); - const regions = this.regions - const absoluteRegion = this.state.filter.split(";") - let region = absoluteRegion[0]; - if (absoluteRegion[0] === "world") { - region = window.region ?? "na" - } - - function nameToURL(name) { - if (typeof name !== "string") { - return "error" - } - return name.replace(/#/g, "-"); - } - - function checkThresholds(thresholds) { - let noThresholds = true; - for (let index = 0; index < thresholds.length; index++) { - if (thresholds[index] !== "-") { - noThresholds = false; - } - } - return noThresholds - } + window.history.replaceState({}, "", "?region=" + filter); + } + this.setState({ filter: filter }); + } + + render() { + try { + const t = this.state.translation; + + if (document.location.pathname.slice(-1) === "/") { + return ; + } + + const challenge = JSON.parse(JSON.stringify(this.state.challenge)); + const regions = this.regions; + const absoluteRegion = this.state.filter.split(";"); + let region = absoluteRegion[0]; + if (absoluteRegion[0] === "world") { + region = window.region ?? "na"; + } + + function nameToURL(name) { + if (typeof name !== "string") { + return "error"; + } + return name.replace(/#/g, "-"); + } + + function checkThresholds(thresholds) { + let noThresholds = true; + for (let index = 0; index < thresholds.length; index++) { + if (thresholds[index] !== "-") { + noThresholds = false; + } + } + return noThresholds; + } + + let filters = [ + , + ]; + for (let i = 0; i < regions.length; i++) { + filters.push( + + ); + } + + let summoner = []; + let warnings = []; + let thresholds = ["-", "-", "-", "-", "-", "-", "-", "-", "-", "-"]; + let percentiles = {}; + for (let i = 0; i < this.tiers.length; i++) { + percentiles[serverToMachineReadable(this.tiers[i])] = + Math.round(11 - (i + 1)) / 10; + } + + let icon = + "https://lolcdn.darkintaqt.com/cdn/np-token/" + challenge["icon_2"]; + + if ( + challenge.challenge.id < 10 || + challenge.challenge.id === 2022000 || + challenge.challenge.id === 2023000 || + challenge.challenge.id === 2024100 || + challenge.challenge.id === 2024200 || + challenge.challenge.id === 2024300 + ) { + if (challenge.challenge.id !== 0) { + if (challenge.challenge.id === 2024100) { + icon = + "https://cdn.darkintaqt.com/lol/static/challenges/2024-1seasonal.svg"; + } else if (challenge.challenge.id === 2024200) { + icon = + "https://cdn.darkintaqt.com/lol/static/challenges/2024-2seasonal.svg"; + } else if (challenge.challenge.id === 2024300) { + icon = + "https://cdn.darkintaqt.com/lol/static/challenges/2024-3seasonal.svg"; + } else { + icon = + "https://cdn.darkintaqt.com/lol/static/challenges/" + + challenge.challenge.translation.name + .toLowerCase() + .replace(" ", "") + + ".svg"; + } + } + } + + let totalLength = this.state.totalLength; + + let isLoading = ""; + // Not loaded yet + if (challenge.icon === 1) { + isLoading = css.loading; + let i = 0; + while (i < 25) { + i++; + summoner.push( + + {i}. + + + +

Loading

+
+ + ... + - + + ); + } - let filters = []; - for (let i = 0; i < regions.length; i++) { - filters.push() + icon = "https://lolcdn.darkintaqt.com/cdn/profileicon/-1"; + } else if ( + challenge.challenge.leaderboard === true || + checkExists(challenge.challenge.tags["leaderboardManuallyEnabled"]) + ) { + thresholds = challenge.stats[serverToMachineReadable(region)]; + percentiles = + challenge.stats["percentiles-" + serverToMachineReadable(region)]; + + if (checkThresholds(thresholds)) { + warnings.push( +
+ This challenge is not enabled in #{absoluteRegion} +
+ ); + } else { + // create list with summoners + let summoners = []; + + let counters = {}; + for (let i = 0; i < regions.length; i++) { + if ( + !absoluteRegion.includes(regions[i]) && + absoluteRegion[0] !== "world" + ) { + continue; } - - let summoner = [] - let warnings = []; - let thresholds = ["-", "-", "-", "-", "-", "-", "-", "-", "-", "-"] - let percentiles = {} - for (let i = 0; i < this.tiers.length; i++) { - percentiles[serverToMachineReadable(this.tiers[i])] = Math.round(11 - (i + 1)) / 10; + for (let ii = 0; ii < challenge.summoner[regions[i]].length; ii++) { + if (!checkExists(counters[regions[i]])) { + counters[regions[i]] = 1; + } + challenge.summoner[regions[i]][ii].push(regions[i]); + challenge.summoner[regions[i]][ii].push(counters[regions[i]]); + summoners.push(challenge.summoner[regions[i]][ii]); + counters[regions[i]]++; } - - let icon = "https://lolcdn.darkintaqt.com/cdn/np-token/" + challenge["icon_2"] - - if (challenge.challenge.id < 10 || challenge.challenge.id === 2022000 || challenge.challenge.id === 2023000 || challenge.challenge.id === 2024100 || challenge.challenge.id === 2024200) { - if (challenge.challenge.id !== 0) { - if (challenge.challenge.id === 2024100) { - icon = "https://cdn.darkintaqt.com/lol/static/challenges/2024-1seasonal.svg" - } else if (challenge.challenge.id === 2024200) { - icon = "https://cdn.darkintaqt.com/lol/static/challenges/2024-2seasonal.svg" - } else { - icon = "https://cdn.darkintaqt.com/lol/static/challenges/" + challenge.challenge.translation.name.toLowerCase().replace(" ", "") + ".svg" - } + } + if (challenge.challenge.reversed === true) { + summoners.sort((a, b) => { + // Order by name if same value and position + if (a[1] === b[1]) { + if (b[6] === a[6]) { + return a[4] - b[4]; } - } - - let totalLength = this.state.totalLength - - let isLoading = "" - // Not loaded yet - if (challenge.icon === 1) { - isLoading = css.loading; - let i = 0; - while (i < 25) { - i++; - summoner.push( - {i}. - - - -

Loading

-
- - ... - - - ) + return a[6] - b[6]; + } + return a[1] - b[1]; + }); + } else { + summoners.sort((a, b) => { + // Order by timestamp if same value and position + if (a[1] === b[1]) { + if (b[6] === a[6]) { + return a[4] - b[4]; } - - icon = "https://lolcdn.darkintaqt.com/cdn/profileicon/-1" - } else if (challenge.challenge.leaderboard === true || checkExists(challenge.challenge.tags["leaderboardManuallyEnabled"])) { - - thresholds = challenge.stats[serverToMachineReadable(region)] - percentiles = challenge.stats["percentiles-" + serverToMachineReadable(region)] - - if (checkThresholds(thresholds)) { - warnings.push(
This challenge is not enabled in #{absoluteRegion}
) - } else { - - // create list with summoners - let summoners = [] - - - let counters = {}; - for (let i = 0; i < regions.length; i++) { - - if (!absoluteRegion.includes(regions[i]) && absoluteRegion[0] !== "world") { continue; } - - for (let ii = 0; ii < challenge.summoner[regions[i]].length; ii++) { - if (!checkExists(counters[regions[i]])) { - counters[regions[i]] = 1 - } - challenge.summoner[regions[i]][ii].push(regions[i]) - challenge.summoner[regions[i]][ii].push(counters[regions[i]]) - summoners.push(challenge.summoner[regions[i]][ii]) - counters[regions[i]]++ - } - - } - if (challenge.challenge.reversed === true) { - summoners.sort((a, b) => { - // Order by name if same value and position - if (a[1] === b[1]) { - if (b[6] === a[6]) { - return a[4] - b[4] - } - return a[6] - b[6] - } - return a[1] - b[1] - }) - } else { - summoners.sort((a, b) => { - // Order by timestamp if same value and position - if (a[1] === b[1]) { - if (b[6] === a[6]) { - return a[4] - b[4] - } - return a[6] - b[6] - } - return b[1] - a[1] - }) - } - - if (summoners.length === 0) { - summoner = [] - } else { - for (let i = 0; i < summoners.length; i++) { - if (i >= totalLength) { - break; - } - const player = summoners[i]; - // let pos = css.normal; - // if (i === 0) { - // pos = css.pos1 - // } else if (i < 10) { - // pos = css.top10 - // } else if (i < 100) { - // pos = css.top100 - // } - let userlink = "/" + player[6] + "/" + nameToURL(player[0]) - - if (player[0] === "%") { - userlink = "/faq" - } - - summoner.push( - {i + 1}. - - - {player[5] === 1 ? : null} - -

{player[0]} {serverToHumanReadable(player[6])}

-
- - {capitalize(t(strtolower(intToTier(player[2]))))} - {beautifyNum(player[1], false)} - ) + return a[6] - b[6]; + } + return b[1] - a[1]; + }); + } + + if (summoners.length === 0) { + summoner = []; + } else { + for (let i = 0; i < summoners.length; i++) { + if (i >= totalLength) { + break; + } + const player = summoners[i]; + // let pos = css.normal; + // if (i === 0) { + // pos = css.pos1 + // } else if (i < 10) { + // pos = css.top10 + // } else if (i < 100) { + // pos = css.top100 + // } + let userlink = "/" + player[6] + "/" + nameToURL(player[0]); + + if (player[0] === "%") { + userlink = "/faq"; + } + + summoner.push( + + {i + 1}. + + + {player[5] === 1 ? ( + + ) : null} + {("This challenge isn't enabled in this {{region}}", { region: absoluteRegion })}
- } else { - warnings.push(challenge.stats["percentiles-" + serverToMachineReadable(region)]) - warnings.push(
Leaderboards aren't enabled for this challenge

Why? Because it is not possible to "scale" in this challenge, as it has a static highest achievable score.
If you think this challenge should have a leaderboard, please create an issue on
GitHub.
) - } - } - - try { - if (checkExists(challenge.challenge.tags["leaderboardManuallyEnabled"])) { - warnings.push(
{t("Leaderboards might be incorrect due to a missing API-endpoint about this challenge. We still update rankings in this leaderboard, if you found a player who should be up here, just look them up.")}
) - } - } catch (error) { - console.warn(error); - } - if (challenge.challenge.reversed) { - warnings.push(
{t("This challenge is reversed. The less your points the better your placement")}
) + placeholderSrc={"https://lolcdn.darkintaqt.com/s/p-cb"} + alt={player[0] + "'s profile image"} + > +

+ {player[0]}{" "} + + {serverToHumanReadable(player[6])} + +

+ + + {capitalize(t(strtolower(intToTier(player[2]))))} + {beautifyNum(player[1], false)} + + ); } + } + } + } else { + thresholds = challenge.challenge.thresholds; + if (checkThresholds(thresholds)) { + summoner = ( +
+ { + ("This challenge isn't enabled in this {{region}}", + { region: absoluteRegion }) + } +
+ ); + } else { + warnings.push( + challenge.stats["percentiles-" + serverToMachineReadable(region)] + ); + warnings.push( +
+ Leaderboards aren't enabled for this challenge +
+
+ + Why? Because it is not possible to "scale" in this challenge, as + it has a static highest achievable score.
+ If you think this challenge should have a leaderboard, please + create an issue on{" "} + + GitHub + + . +
+
+ ); + } + } + + try { + if ( + checkExists(challenge.challenge.tags["leaderboardManuallyEnabled"]) + ) { + warnings.push( +
+ {t( + "Leaderboards might be incorrect due to a missing API-endpoint about this challenge. We still update rankings in this leaderboard, if you found a player who should be up here, just look them up." + )} +
+ ); + } + } catch (error) { + console.warn(error); + } + if (challenge.challenge.reversed) { + warnings.push( +
+ {t( + "This challenge is reversed. The less your points the better your placement" + )} +
+ ); + } + + if (challenge.icon_2 === 0) { + warnings.push( +
+ This leaderboard is "technically" wrong, as the ranking still + includes points from the seasonal 2023 challenges for some players, + which should not be counted towards the total points.{" "} +
+ ); + } + + // if (summoner.length === 0) { + // warnings.push(
No high-ranked summoners yet

Due to API limitations we can only show players ranked MASTER+
) + // } + + let thresholdTable = []; + for (let i = 1; i < thresholds.length; i++) { + let lineThrough = { + color: "#828282", + textDecoration: "none", + textAlign: "center", + }; + if (thresholds[i] === "-" && percentiles[intToTier(i)] === 0) { + lineThrough.textDecoration = "line-through"; + } else { + lineThrough.color = "var(--type,#fff)"; + } - if (challenge.icon_2 === 0) { - warnings.push(
This leaderboard is "technically" wrong, as the ranking still includes points from the seasonal 2023 challenges for some players, which should not be counted towards the total points.
); - } - - // if (summoner.length === 0) { - // warnings.push(
No high-ranked summoners yet

Due to API limitations we can only show players ranked MASTER+
) - // } - - let thresholdTable = [] - for (let i = 1; i < thresholds.length; i++) { - - let lineThrough = { color: "#828282", textDecoration: "none", textAlign: "center" }; - if (thresholds[i] === "-" && percentiles[intToTier(i)] === 0) { - lineThrough.textDecoration = "line-through"; - } else { - lineThrough.color = "var(--type,#fff)" - } - - thresholdTable.unshift(
-

{strtoupper(t(strtolower(intToTier(i))))}

-

{beautifyNum(thresholds[i])}

-

{Math.round(percentiles[intToTier(i)] * 1000) / 10}%

-
) + thresholdTable.unshift( +
+

+ {strtoupper(t(strtolower(intToTier(i))))} +

+

{beautifyNum(thresholds[i])}

+

+ {Math.round(percentiles[intToTier(i)] * 1000) / 10}% +

+
+ ); + } + + let content = ( + +
-
- {challenge.challenge.translation.name -

{challenge.challenge.translation.name}

-

- {challenge.challenge.translation.description} {challenge.timestamp - ? ({t("Updated")} ) - : - } - - {challenge.title.length > 0 - ?
- Title{challenge.title[0][1]} -
- : null} - -

- -
- -
start[filter]).join(" ")}> - {filters} -
- -
- -
-
-

{t("Thresholds")}

- {t("How many players have reached a tier")} -
-
- -
-

{t("Tier")}

-

{t("Points")}

-

%

-
- - {thresholdTable} -
-
- - {warnings} - - {challenge.text !== false ?
-
-

{t("Info")}

- {t("All you need to know about this challenge")} -
-
" + challenge.text.replace(/---\n/ig, "

").replace(/\n/g, "
") + "

" }}>
-
: null - } - - {challenge.challenge.translation.name !== "Loading" ? -
- -
: null} - - {/* FIX: Disabled since buggy */} -
-
-

{t("Average Progress")}

- {t("Points per game")} -
- - -
-
- -
-
-

{t("\"{{challenge}}\" Leaderboard", { challenge: challenge.challenge.translation.name })}

- {this.state.filter === "world" ? t("Global Ranking") : t("Regional Ranking")} -
- - - - - - - - - {summoner} - -
{t("Position")}{t("Summoner")}{t("Tier")}{t("Points")}
-
- ; - - if (this.state.message !== -1) { - content = this.state.message; + > + {challenge.challenge.translation.name +

{challenge.challenge.translation.name}

+

+ {challenge.challenge.translation.description}{" "} + {challenge.timestamp ? ( + + ({t("Updated")}{" "} + ) + + ) : ( + + )} + {challenge.title.length > 0 ? ( + +
+ + Title + {challenge.title[0][1]} + +
+ ) : null} +

+
+ +
start[filter]) + .join(" ") } - - return - {content} - - } catch (e) { - console.warn(e); - return

an error occurred

- } + > + {filters} +
+ +
+
+
+

{t("Thresholds")}

+ {t("How many players have reached a tier")} +
+
+
+

{t("Tier")}

+

{t("Points")}

+

%

+
+ + {thresholdTable} +
+
+ + {warnings} + + {challenge.text !== false ? ( +
+
+

{t("Info")}

+ + {" "} + {t("All you need to know about this challenge")}{" "} + +
+
" + + challenge.text + .replace( + /---\n/gi, + "

" + ) + .replace(/\n/g, "
") + + "

", + }} + >
+
+ ) : null} + + {challenge.challenge.translation.name !== "Loading" ? ( +
+ +
+ ) : null} + + {/* FIX: Disabled since buggy */} +
+
+

{t("Average Progress")}

+ {t("Points per game")} +
+ + +
+
+ +
+
+

+ {t('"{{challenge}}" Leaderboard', { + challenge: challenge.challenge.translation.name, + })} +

+ + {" "} + {this.state.filter === "world" + ? t("Global Ranking") + : t("Regional Ranking")}{" "} + +
+ + + + + + + + + {summoner} + +
{t("Position")}{t("Summoner")}{t("Tier")}{t("Points")}
+
+
+ ); + + if (this.state.message !== -1) { + content = this.state.message; + } + + return {content}; + } catch (e) { + console.warn(e); + return

an error occurred

; } + } } -export default withTranslation()(Challenge) \ No newline at end of file +export default withTranslation()(Challenge); diff --git a/src/module/Challenges.js b/src/module/Challenges.js index dc02d53..8fd5e21 100644 --- a/src/module/Challenges.js +++ b/src/module/Challenges.js @@ -372,7 +372,8 @@ class Challenges extends Component { if ( parentId !== 2022000 && parentId !== 2023000 && - parentId !== 2024100 + parentId !== 2024100 && + parentId !== 2024200 ) { continue; } @@ -612,12 +613,12 @@ class Challenges extends Component { legacy Legacy -
+ constructor(props) { + super(props); + this.challenges = props.content; + this.updateCompontent = this.updateCompontent.bind(this); + this.state = { + content:
, + }; + } + + componentDidMount() { + get( + "https://challenges.darkintaqt.com/api/v5/c/?id=2024300", + this.updateCompontent + ); + } + + updateCompontent(leaderboards) { + // console.log(leaderboards); + + // let challenges = this.challenges + + let regions = config.regions; + let summoner = []; + let counters = {}; + + for (let i = 0; i < regions.length; i++) { + for (let ii = 0; ii < leaderboards.summoner[regions[i]].length; ii++) { + if (!checkExists(counters[regions[i]])) { + counters[regions[i]] = 1; } + leaderboards.summoner[regions[i]][ii].push(regions[i]); + leaderboards.summoner[regions[i]][ii].push(counters[regions[i]]); + summoner.push(leaderboards.summoner[regions[i]][ii]); + counters[regions[i]]++; + } } - - componentDidMount() { - - get("https://challenges.darkintaqt.com/api/v5/c/?id=2024200", this.updateCompontent) - - } - - updateCompontent(leaderboards) { - - // console.log(leaderboards); - - // let challenges = this.challenges - - let regions = config.regions - let summoner = [] - let counters = {}; - - for (let i = 0; i < regions.length; i++) { - for (let ii = 0; ii < leaderboards.summoner[regions[i]].length; ii++) { - if (!checkExists(counters[regions[i]])) { - counters[regions[i]] = 1 - } - leaderboards.summoner[regions[i]][ii].push(regions[i]) - leaderboards.summoner[regions[i]][ii].push(counters[regions[i]]) - summoner.push(leaderboards.summoner[regions[i]][ii]) - counters[regions[i]]++ - } - + summoner.sort((a, b) => { + if (a[1] === b[1]) { + if (b[5] === a[5]) { + return a[0] < b[0] ? -1 : +(a[0] > b[0]); } - summoner.sort((a, b) => { - if (a[1] === b[1]) { - if (b[5] === a[5]) { - return a[0] < b[0] ? -1 : +(a[0] > b[0]) - } - return a[5] - b[5] - } - return b[1] - a[1] - }); - - let topPlayer = [] - - for (let i = 0; i < 5; i++) { - const player = summoner[i]; - topPlayer.push(
-

{i + 1}.

- -

- {player[0]} -

-

#{player[6]}

-
); - } - - this.setState({ - content: -
-

Seasonal 2024 Split Leaderboards

- -
- Check the final Leaderboards for the 2024 seasonal challenges split 2.

Just click here to get to the leaderboards. -
- -
-
- {topPlayer} -
- -
- }) - + return a[5] - b[5]; + } + return b[1] - a[1]; + }); + + let topPlayer = []; + + for (let i = 0; i < 5; i++) { + const player = summoner[i]; + topPlayer.push( +
+

{i + 1}.

+ +

{player[0]}

+

#{player[6]}

+
+ ); } - - render() { - return this.state.content - } -} \ No newline at end of file + this.setState({ + content: ( + +
+

Seasonal 2024 Split Leaderboards

+ +
+ Check the final Leaderboards for the 2024 seasonal challenges + split 2.
+
+ Just click here to get to the leaderboards. +
+
+
{topPlayer}
+
+ ), + }); + } + + render() { + return this.state.content; + } +} diff --git a/src/module/user/UserChallenges.js b/src/module/user/UserChallenges.js index a900a0d..9d48044 100644 --- a/src/module/user/UserChallenges.js +++ b/src/module/user/UserChallenges.js @@ -1,466 +1,579 @@ import { Component, Fragment } from "react"; import config from "../../config"; -import filterCSS from "../../css/filter.module.css" +import filterCSS from "../../css/filter.module.css"; import { setCookie } from "../../func/cookiefunctions"; -import { toggleValue } from "../../func/arrayManipulationFunctions.js" +import { toggleValue } from "../../func/arrayManipulationFunctions.js"; import ChallengeObject from "../ChallengeObject"; -import challengeCSS from "../../css/challengeObject.module.css" +import challengeCSS from "../../css/challengeObject.module.css"; -import { beautifyNum } from "../../func/beautify.js" -import { checkExists } from "../../func/arrayManipulationFunctions.js" +import { beautifyNum } from "../../func/beautify.js"; +import { checkExists } from "../../func/arrayManipulationFunctions.js"; import { intToTier } from "../../func/tierFunctions"; -import Timestamp from "react-timestamps" +import Timestamp from "react-timestamps"; -import css from "../../css/user.module.css" +import css from "../../css/user.module.css"; import orderChallenges, { getNextLevel } from "./orderChallenges"; -import Loader from "../Loader" +import Loader from "../Loader"; import { withTranslation } from "react-i18next"; import { capitalize } from "../../func/stringManipulation"; import getChallenge from "../../func/getChallenge"; -import { getStorage, setStorage, storageKeys } from "../../func/sessionStorageFunctions"; - +import { + getStorage, + setStorage, + storageKeys, +} from "../../func/sessionStorageFunctions"; class UserChallenges extends Component { - constructor(props) { - super(props) - - - this.changeFilter = this.changeFilter.bind(this) - this.changeExtraFilter = this.changeExtraFilter.bind(this) - this.toggleMasterTierSorting = this.toggleMasterTierSorting.bind(this) - this.togglePointsAvailableSorting = this.togglePointsAvailableSorting.bind(this) - this.toggleCapstones = this.toggleCapstones.bind(this); - - this.changeDisplayMethod = this.changeDisplayMethod.bind(this) - this.search = this.search.bind(this); - - this.props = props; - - const filter = getStorage(storageKeys.userFilter, "level"); - const alphabet = filter === "alphabetic-a-z" ? "z-a" : "a-z"; - - this.state = { - alphabet, - orderByMaster: getStorage(storageKeys.masterOnly, false), - orderByPoints: getStorage(storageKeys.pointsOnly, false), - capstones: getStorage(storageKeys.capstones, false), - placeholder: window.compactMode, - filter, - filters: getStorage(storageKeys.userFilters, { - "category": [], - "type": [], - "gamemode": [], - }), - translation: props.t, - search: "" - } - + constructor(props) { + super(props); + + this.changeFilter = this.changeFilter.bind(this); + this.changeExtraFilter = this.changeExtraFilter.bind(this); + this.toggleMasterTierSorting = this.toggleMasterTierSorting.bind(this); + this.togglePointsAvailableSorting = + this.togglePointsAvailableSorting.bind(this); + this.toggleCapstones = this.toggleCapstones.bind(this); + + this.changeDisplayMethod = this.changeDisplayMethod.bind(this); + this.search = this.search.bind(this); + + this.props = props; + + const filter = getStorage(storageKeys.userFilter, "level"); + const alphabet = filter === "alphabetic-a-z" ? "z-a" : "a-z"; + + this.state = { + alphabet, + orderByMaster: getStorage(storageKeys.masterOnly, false), + orderByPoints: getStorage(storageKeys.pointsOnly, false), + capstones: getStorage(storageKeys.capstones, false), + placeholder: window.compactMode, + filter, + filters: getStorage(storageKeys.userFilters, { + category: [], + type: [], + gamemode: [], + }), + translation: props.t, + search: "", + }; + } + + toggleMasterTierSorting() { + setStorage(storageKeys.masterOnly, !this.state.orderByMaster); + + this.setState({ + orderByMaster: !this.state.orderByMaster, + }); + } + + toggleCapstones() { + setStorage(storageKeys.capstones, !this.state.capstones); + + this.setState({ + capstones: !this.state.capstones, + }); + } + + togglePointsAvailableSorting() { + setStorage(storageKeys.pointsOnly, !this.state.orderByPoints); + + this.setState({ + orderByPoints: !this.state.orderByPoints, + }); + } + + changeFilter(e) { + const user = this.props.summoner; + + if (user.challenges.length !== 0) { + const button = e.currentTarget; + const filter = this.state.filter; + + if (filter === button.id) { + return; + } + + if (filter === "alphabetic-a-z") { + document + .getElementById("alphabetic-z-a") + .classList.remove(filterCSS["selected"]); + } else if (filter === "alphabetic-z-a") { + document + .getElementById("alphabetic-a-z") + .classList.remove(filterCSS["selected"]); + } else { + document.getElementById(filter).classList.remove(filterCSS["selected"]); + } + + button.classList.add(filterCSS["selected"]); + + let tempFilter = button.id; + let alphabetVar = this.state.alphabet; + + if (tempFilter === "alphabetic-a-z" && alphabetVar === "a-z") { + alphabetVar = "z-a"; + } + + if (tempFilter === "alphabetic-z-a" && alphabetVar === "z-a") { + alphabetVar = "a-z"; + } + + this.setState({ filter: tempFilter, alphabet: alphabetVar }); + setStorage(storageKeys.userFilter, tempFilter); } - - toggleMasterTierSorting() { - - setStorage(storageKeys.masterOnly, !this.state.orderByMaster); - - this.setState({ - orderByMaster: !this.state.orderByMaster - }) + } + + changeExtraFilter(e) { + const user = this.props.summoner; + if (user.challenges.length !== 0) { + let filters = this.state.filters; + + const toggle = toggleValue( + filters[e.currentTarget.getAttribute("type")], + e.currentTarget.id + ); + + if (toggle.method === true) { + e.currentTarget.classList.add(filterCSS["selected"]); + } else { + e.currentTarget.classList.remove(filterCSS["selected"]); + } + + this.setState({ filters: filters }); + setStorage(storageKeys.userFilters, filters); } - - toggleCapstones() { - - setStorage(storageKeys.capstones, !this.state.capstones); - - this.setState({ - capstones: !this.state.capstones - }) - + } + + changeDisplayMethod() { + setCookie("filter", JSON.stringify(!this.state.placeholder)); + window.compactMode = !this.state.placeholder; + this.setState({ placeholder: !this.state.placeholder }); + } + + search(e) { + this.setState({ search: e.currentTarget.value }); + } + + componentDidUpdate() { + const filters = [ + this.state.filter, + ...Object.values(this.state.filters).flat(), + ]; + + for (const id of filters) { + if (document.getElementById(id)) { + document.getElementById(id).classList.add(filterCSS["selected"]); + } } - - togglePointsAvailableSorting() { - - setStorage(storageKeys.pointsOnly, !this.state.orderByPoints); - - this.setState({ - orderByPoints: !this.state.orderByPoints - }) + } + + render() { + const t = this.state.translation; + const user = JSON.parse(JSON.stringify(this.props.summoner)); + + if (user.challenges.length === 0) { + return ( +
+ +

+ Loading Challenges... +

+
+ ); } - - changeFilter(e) { - const user = this.props.summoner - - if (user.challenges.length !== 0) { - - const button = e.currentTarget - const filter = this.state.filter - - if (filter === button.id) { - return - } - - if (filter === "alphabetic-a-z") { - document.getElementById("alphabetic-z-a").classList.remove(filterCSS["selected"]) - } else if (filter === "alphabetic-z-a") { - document.getElementById("alphabetic-a-z").classList.remove(filterCSS["selected"]) - } else { - document.getElementById(filter).classList.remove(filterCSS["selected"]) - } - - button.classList.add(filterCSS["selected"]) - - let tempFilter = button.id - let alphabetVar = this.state.alphabet - - if (tempFilter === "alphabetic-a-z" && alphabetVar === "a-z") { - alphabetVar = "z-a" - } - - if (tempFilter === "alphabetic-z-a" && alphabetVar === "z-a") { - alphabetVar = "a-z" - - } - - this.setState({ filter: tempFilter, alphabet: alphabetVar }) - setStorage(storageKeys.userFilter, tempFilter); - + document.title = `${user.summonerName}'s Challenge Progress Overview`; + + const server = this.props.server; + + const filter = this.state.filter; + + let challengesOrdered = orderChallenges( + user.challenges, + this.state.filter, + this.state.filters, + this.state.orderByMaster, + this.state.orderByPoints, + this.state.search, + this.state.capstones + ); + + let challenges = challengesOrdered + .map((challenge) => { + if (challenge[0] !== 0 && challenge[0] < 10) { + return null; } - } - - - changeExtraFilter(e) { - - - - const user = this.props.summoner - if (user.challenges.length !== 0) { - - let filters = this.state.filters - - const toggle = toggleValue(filters[e.currentTarget.getAttribute("type")], e.currentTarget.id) - - if (toggle.method === true) { - - e.currentTarget.classList.add(filterCSS["selected"]) - - } else { - - e.currentTarget.classList.remove(filterCSS["selected"]) - - } - - this.setState({ filters: filters }) - setStorage(storageKeys.userFilters, filters); + const tier = intToTier(challenge[1]); + + let leaderboardposition = ""; + let position, + next, + previousPositions = 1; + let nexttier = getNextLevel(tier); + + const c = challenge[6]; + + if (c.leaderboard === true && challenge[5].length > 1) { + switch (tier) { + case "GRANDMASTER": + previousPositions = c["leaderboardThresholds"][3] ?? 1; + break; + case "MASTER": + previousPositions = c["leaderboardThresholds"][5] ?? 1; + break; + default: + previousPositions = 1; + break; + } + position = + "#" + beautifyNum(previousPositions - 1 + challenge[5][1], false); + + if (challenge[5][1] <= 100 && challenge[5].length === 4) { + position = position + " (#" + challenge[5][3] + " World)"; + } + position += " - "; } - } - - changeDisplayMethod() { - setCookie("filter", JSON.stringify(!this.state.placeholder)); - window.compactMode = !this.state.placeholder - this.setState({ placeholder: !this.state.placeholder }); - } - - search(e) { - this.setState({ search: e.currentTarget.value }) - } - - componentDidUpdate() { - const filters = [this.state.filter, ...Object.values(this.state.filters).flat()]; - - for (const id of filters) { - if (document.getElementById(id)) { - document.getElementById(id).classList.add(filterCSS["selected"]); - } - } - } - - - render() { - - const t = this.state.translation - const user = JSON.parse(JSON.stringify(this.props.summoner)); - - if (user.challenges.length === 0) { - - return
- -

Loading Challenges...

-
+ if (this.state.orderByMaster === true) { + nexttier = "MASTER"; } - document.title = `${user.summonerName}'s Challenge Progress Overview` - - const server = this.props.server - - const filter = this.state.filter - - - let challengesOrdered = orderChallenges(user.challenges, this.state.filter, this.state.filters, this.state.orderByMaster, this.state.orderByPoints, this.state.search, this.state.capstones) - - - let challenges = challengesOrdered.map((challenge) => { - - if (challenge[0] !== 0 && challenge[0] < 10) { - return null - } - - const tier = intToTier(challenge[1]) - - let leaderboardposition = "" - let position, next, previousPositions = 1; - let nexttier = getNextLevel(tier) - - const c = challenge[6] - - - if (c.leaderboard === true && challenge[5].length > 1) { - switch (tier) { - case "GRANDMASTER": - previousPositions = c["leaderboardThresholds"][3] ?? 1 - break; - case "MASTER": - previousPositions = c["leaderboardThresholds"][5] ?? 1 - break; - default: - previousPositions = 1 - break; - } - position = "#" + beautifyNum((previousPositions - 1) + challenge[5][1], false); - if (challenge[5][1] <= 100 && challenge[5].length === 4) { + next = 1; + if (checkExists(c["thresholds"][nexttier])) { + next = c["thresholds"][nexttier]; + } else if (!checkExists(c["thresholds"][tier])) { + let stop = false; + let i = 0; - position = position + " (#" + challenge[5][3] + " World)"; - } - position += " - "; - - } - - if (this.state.orderByMaster === true) { - nexttier = "MASTER" - } - - next = 1 + while (stop === false && i < 10) { + i++; + nexttier = getNextLevel(nexttier); if (checkExists(c["thresholds"][nexttier])) { - next = c["thresholds"][nexttier] - } else if (!checkExists(c["thresholds"][tier])) { - - let stop = false; - let i = 0; - - while (stop === false && i < 10) { - i++; - nexttier = getNextLevel(nexttier); - if (checkExists(c["thresholds"][nexttier])) { - next = c["thresholds"][nexttier] - stop = true; - } - - if (nexttier === "CHALLENGER") { - stop = true; - } - } - } else { - next = c["thresholds"][tier] - } - - if (tier === "CHALLENGER" && this.state.orderByMaster === false) { - if (c.leaderboard === true) { - // leaderboards, not #1 - next = c["leaderboardThresholds"][0] ?? 0 - nexttier = "CROWN"; - } else { - // No leaderboards, so maxed - nexttier = "MAXED" - } - if ((previousPositions - 1) + challenge[5][1] === 1) { - // leaderboards, #1 - nexttier = "FIRST"; - } - } - - let tags = [] - - if (checkExists(challenge[8])) { - tags.push() - } - - if (checkExists(challenge[7]) && challenge[7] !== "none") { - tags.push() + next = c["thresholds"][nexttier]; + stop = true; } - - - - if (filter === "timestamp") { - leaderboardposition = - } else { - leaderboardposition = {position}{t("Top {{percent}}%", { percent: (Math.round(challenge[5][0] * 10000) / 100) })} + if (nexttier === "CHALLENGER") { + stop = true; } + } + } else { + next = c["thresholds"][tier]; + } + if (tier === "CHALLENGER" && this.state.orderByMaster === false) { + if (c.leaderboard === true) { + // leaderboards, not #1 + next = c["leaderboardThresholds"][0] ?? 0; + nexttier = "CROWN"; + } else { + // No leaderboards, so maxed + nexttier = "MAXED"; + } + if (previousPositions - 1 + challenge[5][1] === 1) { + // leaderboards, #1 + nexttier = "FIRST"; + } + } - return + ); + } + if (checkExists(challenge[7]) && challenge[7] !== "none") { + tags.push(); + } - if (challenges.length === 0) { - challenges =

Is it a bug? Is it a feature?

No! There are just no challenges within the current filters.

+ if (filter === "timestamp") { + leaderboardposition = ( + + + + + + + + + ); + } else { + leaderboardposition = ( + + {position} + {t("Top {{percent}}%", { + percent: Math.round(challenge[5][0] * 10000) / 100, + })} + + ); } - return + return ( + + Is it a bug? Is it a feature? +
+
+ No! There are just no challenges within the current filters. +

+ ); + } -
-
-
- - - - - - - - - -
-

Filter

-
-

{t("Order by")}

- - - - - - - - - - - -
- -
-

{t("Category")}

- - - - - - - - - - - - - - - - - -
- -
-

{t("Gamemode")}

- - - - - - - - - -
- -
-

- - Click here to get any questions about this page answered. - -

+ return ( + +
+
+
+ + + + + + + +
+

Filter

+
+

{t("Order by")}

+ + + + + + + + + +
- -
- - {challenges} +
+

{t("Category")}

+ + + + + + + + + + + + + + + +
- - } +
+

{t("Gamemode")}

+ + + + + + + + +
+
+

+ + Click{" "} + + here + {" "} + to get any questions about this page answered. + +

+
+ +
+ + {challenges} +
+ + ); + } } -export default withTranslation()(UserChallenges) +export default withTranslation()(UserChallenges); diff --git a/src/module/user/orderChallenges.js b/src/module/user/orderChallenges.js index 0d0c700..9015830 100644 --- a/src/module/user/orderChallenges.js +++ b/src/module/user/orderChallenges.js @@ -171,7 +171,8 @@ export function removeUnnecessaryChallenges( if ( parentId !== 2022000 && parentId !== 2023000 && - parentId !== 2024100 + parentId !== 2024100 && + parentId !== 2024200 ) { return null; } @@ -196,7 +197,8 @@ export function removeUnnecessaryChallenges( challenge[8].parent === 2022000 || challenge[8] === 2023000 || challenge[8] === 2024100 || - challenge[8] === 2024200 + challenge[8] === 2024200 || + challenge[8] === 2024300 ) { return null; } diff --git a/src/module/user/statsCalculateTotalPoints.js b/src/module/user/statsCalculateTotalPoints.js index a96c09b..48806f4 100644 --- a/src/module/user/statsCalculateTotalPoints.js +++ b/src/module/user/statsCalculateTotalPoints.js @@ -3,33 +3,37 @@ import { intToTier } from "../../func/tierFunctions"; import config from "../../config"; export default function statsCalculateTotalPoints(challenges) { + challenges = removeUnnecessaryChallenges(challenges, { + gamemode: [], + type: [], + category: [], + }); - challenges = removeUnnecessaryChallenges(challenges, { "gamemode": [], "type": [], "category": [] }) + let tiers = {}; + for (let i = 0; i < config.tiers.length; i++) { + tiers[config.tiers[i]] = 0; + } - let tiers = {} - for (let i = 0; i < config.tiers.length; i++) { - tiers[config.tiers[i]] = 0 - } - - // console.log("-----"); + // console.log("-----"); - for (let i = 0; i < challenges.length; i++) { - const challenge = challenges[i]; + for (let i = 0; i < challenges.length; i++) { + const challenge = challenges[i]; - if (challenge[0] > 10 - && challenge[6].parent !== "0" // all legacy - && challenge[8] !== 2022000 // 2022 capstone - && challenge[8] !== 2023000 // 2023 capstone - && challenge[8] !== 601000 // arena brawler capstone - && challenge[8] !== 602000 // arena champion capstone - && challenge[8] !== 2024100 // seasonal 2024 capstone - && challenge[8] !== 2024200 // seasonal 2024 capstone - && challenge[8] !== 603000 // swarm - && challenge[6].state === "ENABLED" - ) { - tiers[intToTier(challenge[1])] += 1 - } + if ( + challenge[0] > 10 && + challenge[6].parent !== "0" && // all legacy + challenge[8] !== 2022000 && // 2022 capstone + challenge[8] !== 2023000 && // 2023 capstone + challenge[8] !== 601000 && // arena brawler capstone + challenge[8] !== 602000 && // arena champion capstone + challenge[8] !== 2024100 && // seasonal 2024 capstone + challenge[8] !== 2024200 && // seasonal 2024 capstone + challenge[8] !== 2023200 && // seasonal 2024 capstone + challenge[8] !== 603000 && // swarm + challenge[6].state === "ENABLED" + ) { + tiers[intToTier(challenge[1])] += 1; } - return tiers - -} \ No newline at end of file + } + return tiers; +}