Skip to content

Commit 29bed1a

Browse files
committed
- Add function to update tableRow when a material is obtained, instead of re-building the table every time.
- As a result, buildTable now only runs at app load, adds all available materials stored in app, and hids any rows where quantity is 0 - Re-added material highlight when a material is obtained.
1 parent 4b2adcc commit 29bed1a

File tree

2 files changed

+70
-28
lines changed

2 files changed

+70
-28
lines changed

src/css/style.css

+41-22
Original file line numberDiff line numberDiff line change
@@ -72,55 +72,74 @@ html {
7272
}
7373

7474
.row {
75-
text-align: center;
75+
text-align: center;
7676
}
7777

7878
.matHeader {
79-
border-top: white solid .5px;
80-
background: url('https://runeapps.org/nis/alt1-currentskin/nisbutton.png') 0px -100%/24px 400% repeat content-box;
81-
color: black;
82-
font-family: 'trajan-pro-3';
79+
border-top: white solid 0.5px;
80+
background: url("https://runeapps.org/nis/alt1-currentskin/nisbutton.png") 0px -100%/24px 400% repeat content-box;
81+
color: black;
82+
font-family: "trajan-pro-3";
8383
}
8484

85-
.mats>.row,
85+
.mats > .row,
8686
.matHeader * {
87-
border-bottom: white solid .5px;
88-
border-right: white solid .5px;
87+
border-bottom: white solid 0.5px;
88+
border-right: white solid 0.5px;
8989
}
9090

9191
.matHeader,
92-
.mats>.row * {
93-
border-left: white solid .5px;
92+
.mats > .row * {
93+
border-left: white solid 0.5px;
9494
}
9595

9696
.scroll {
97-
overflow-y: scroll;
98-
height: calc(100% - 39px);
97+
overflow-y: scroll;
98+
height: calc(100% - 39px);
9999
}
100100

101101
.scroll::-webkit-scrollbar {
102-
display: none;
102+
display: none;
103103
}
104104

105105
body.nis:not(.artefact)::-webkit-scrollbar {
106-
display: none;
106+
display: none;
107107
}
108108

109109
body.nis:not(.artefact) {
110-
overflow: scroll !important;
111-
/* min-width: 315px; */
112-
height: calc(100vh - 10px);
110+
overflow: scroll !important;
111+
/* min-width: 315px; */
112+
height: calc(100vh - 10px);
113113
}
114114

115115
.container * {
116-
font-weight: bold;
117-
font-size: 10pt;
116+
font-weight: bold;
117+
font-size: 10pt;
118118
}
119119

120120
.container {
121-
margin-top: 10px
121+
margin-top: 10px;
122122
}
123123

124124
.nisbutton {
125-
font-size: 8pt !important;
126-
}
125+
font-size: 8pt !important;
126+
}
127+
128+
.hide {
129+
display: none;
130+
}
131+
132+
.new {
133+
animation: flashNew 1s;
134+
}
135+
136+
@keyframes flashNew {
137+
from {
138+
background-color: lime;
139+
color: black;
140+
}
141+
to {
142+
background-color: none;
143+
color: none;
144+
}
145+
}

src/index.ts

+29-6
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,29 @@ function processMaterials(chatLine) {
256256
};
257257

258258
updateSaveData({ materials: material });
259+
updateRow(material.name);
259260
}
260261
}
261262

263+
function updateRow(matName) {
264+
const mats = getSaveData("materials");
265+
266+
const row = document.querySelector(`#${matName}`) as HTMLElement;
267+
const qty = document.querySelector(`#${matName} .quantity`) as HTMLElement;
268+
269+
qty.innerText = mats[matName].qty;
270+
271+
if (row.classList.contains("hide")) {
272+
row.classList.remove("hide");
273+
}
274+
275+
row.classList.add("new");
276+
row.addEventListener("animationend", () => {
277+
row.classList.remove("new");
278+
});
279+
280+
}
281+
262282
function buildTable() {
263283
const mats = getSaveData("materials");
264284
if (!mats) {
@@ -269,11 +289,14 @@ function buildTable() {
269289

270290
const matNames = Object.keys(mats).sort();
271291
for (let mat of matNames) {
272-
if (mats[mat]["qty"] > 0) {
273-
document
274-
.querySelector(`.${mats[mat]["type"]} > .col`)
275-
.insertAdjacentHTML("beforeend", `<div class='mats row'><div class='mats col'>${mat}</div><div class='col'>${mats[mat]["qty"]}</div></div>`);
276-
}
292+
document
293+
.querySelector(`.${mats[mat]["type"]} > .col`)
294+
.insertAdjacentHTML(
295+
"beforeend",
296+
`<div id="${mat}" class='mats row ${mats[mat]["qty"] == 0 ? "hide" : ""}'><div class='mats col'>${mat}</div><div class='col quantity'>${
297+
mats[mat]["qty"]
298+
}</div></div>`
299+
);
277300
}
278301
}
279302

@@ -333,6 +356,7 @@ exportButton.addEventListener("click", function () {
333356
// Factory Reset logic
334357
clearButton.addEventListener("click", function () {
335358
localStorage.removeItem(appName);
359+
sessionStorage.removeItem(`${appName}chatHistory`)
336360
location.reload();
337361
});
338362

@@ -348,7 +372,6 @@ async function updateSaveData(...dataset) {
348372
console.log(value);
349373
lsData[name][value["name"]].qty += Number(value["quantity"]);
350374
localStorage.setItem(appName, JSON.stringify(lsData));
351-
buildTable();
352375
continue;
353376
}
354377
}

0 commit comments

Comments
 (0)