From 3c4abaeb5c22e1de68b2d2dd0715bb55415b5167 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Thu, 25 Feb 2021 17:36:58 +0100 Subject: [PATCH] [MIRROR] Improves the chem recipe lookup by reducing it's lag and other requested changes from feedback (#3649) * Improves the chem recipe lookup by reducing it's lag and other requested changes from feedback (#57156) So the recipe lookup is considerably laggier than it was testing locally, someone suggested I paginate the big list so less of it has to load, so that's what I did! * Improves the chem recipe lookup by reducing it's lag and other requested changes from feedback Co-authored-by: Thalpy <33956696+Thalpy@users.noreply.github.com> --- code/modules/reagents/chemistry/holder.dm | 4 + tgui/packages/tgui/interfaces/Reagents.js | 280 +++++++++++++++------- 2 files changed, 204 insertions(+), 80 deletions(-) diff --git a/code/modules/reagents/chemistry/holder.dm b/code/modules/reagents/chemistry/holder.dm index 19b666d2d82..8b7b7abf619 100644 --- a/code/modules/reagents/chemistry/holder.dm +++ b/code/modules/reagents/chemistry/holder.dm @@ -1634,6 +1634,8 @@ if(reagent.chemical_flags & REAGENT_DEAD_PROCESS) data["reagent_mode_reagent"] += list("deadProcess" = TRUE) + else + data["reagent_mode_reagent"] = null //reaction lookup data if (ui_reaction_id) @@ -1733,6 +1735,8 @@ tooltip_bool = TRUE data["reagent_mode_recipe"]["catalysts"] += list(list("name" = reagent.name, "id" = reagent.type, "ratio" = reaction.required_catalysts[reagent.type], "color" = color_r, "tooltipBool" = tooltip_bool, "tooltip" = tooltip)) data["reagent_mode_recipe"]["isColdRecipe"] = reaction.is_cold_recipe + else + data["reagent_mode_recipe"] = null return data diff --git a/tgui/packages/tgui/interfaces/Reagents.js b/tgui/packages/tgui/interfaces/Reagents.js index 99ca708f255..ffd76247b11 100644 --- a/tgui/packages/tgui/interfaces/Reagents.js +++ b/tgui/packages/tgui/interfaces/Reagents.js @@ -1,5 +1,5 @@ import { useBackend, useLocalState } from '../backend'; -import { Button, Icon, LabeledList, Section, Stack, Table } from '../components'; +import { Button, Icon, LabeledList, NumberInput, Section, Stack, Table } from '../components'; import { Window } from '../layouts'; import { ReagentLookup } from './common/ReagentLookup'; import { RecipeLookup } from './common/RecipeLookup'; @@ -42,6 +42,8 @@ export const Reagents = (props, context) => { { flag: bitflags.COMPETITIVE, icon: "recycle" }, ]; + const [page, setPage] = useLocalState(context, "page", 1); + return ( { tooltip="When enabled the displayed reaction will automatically display ongoing reactions in the associated beaker." onClick={() => act('beaker_sync')} /> @@ -172,49 +221,73 @@ const TagBox = (props, context) => { @@ -222,31 +295,46 @@ const TagBox = (props, context) => { @@ -256,6 +344,7 @@ const TagBox = (props, context) => { const RecipeLibrary = (props, context) => { const { act, data } = useBackend(context); + const [page, setPage] = useLocalState(context, "page", 1); const { flagIcons } = props; const { selectedBitflags, @@ -281,6 +370,10 @@ const RecipeLibrary = (props, context) => { const bookmarkArray = Array.from(bookmarkedReactions); + const startIndex = 50 * (page-1); + + const endIndex = 50 * page; + const visibleReactions = bookmarkMode ? bookmarkArray : master_reaction_list.filter(reaction => ( @@ -290,6 +383,8 @@ const RecipeLibrary = (props, context) => { && matchReagents(reaction) )); + const pageIndexMax = Math.ceil(visibleReactions.length/50); + const addBookmark = bookmark => { bookmarkedReactions.add(bookmark); }; @@ -305,18 +400,40 @@ const RecipeLibrary = (props, context) => { title={bookmarkMode ? "Bookmarked recipes" : "Possible recipes"} buttons={( <> - Linked beaker: {linkedBeaker+" "} + Beaker: {linkedBeaker+" "}