-
Notifications
You must be signed in to change notification settings - Fork 949
Expand file tree
/
Copy pathquickTools.js
More file actions
91 lines (80 loc) · 2.11 KB
/
quickTools.js
File metadata and controls
91 lines (80 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import "./style.scss";
import Page from "components/page";
import items, { description } from "components/quickTools/items";
import WCPage from "components/WebComponents/wcPage";
import select from "dialogs/select";
import actionStack from "lib/actionStack";
import settings from "lib/settings";
import helpers from "utils/helpers";
export default function QuickTools() {
const $page = Page(strings["shortcut buttons"]);
render($page);
$page.addEventListener("click", clickHandler);
actionStack.push({
id: "quicktools-settings",
action: $page.hide,
});
$page.onhide = () => {
actionStack.remove("quicktools-settings");
helpers.hideAd();
};
app.append($page);
helpers.showAd();
}
/**
* Render the page
* @param {WCPage} $page
*/
function render($page) {
$page.body = (
<div className="main" id="quicktools-settings">
{(() => {
const totalRows = settings.QUICKTOOLS_ROWS * settings.QUICKTOOLS_GROUPS;
const limit = settings.QUICKTOOLS_GROUP_CAPACITY;
const rows = [];
for (let i = 0; i < totalRows; i++) {
const row = [];
for (let j = 0; j < limit; j++) {
const count = i * limit + j;
const index = settings.value.quicktoolsItems[count];
row.push(<Item {...items[index]} index={count} />);
}
rows.push(<div className="row buttons-container section">{row}</div>);
}
return rows;
})()}
</div>
);
}
/**
* Create a quicktools settings item
* @param {object} param0
* @param {string} param0.icon
* @param {string} param0.letters
* @param {number} param0.index
* @returns
*/
function Item({ icon, letters, index }) {
return (
<span
data-index={index}
className={`icon ${icon}`}
data-letters={letters}
></span>
);
}
/**
* Click handler for page
* @param {MouseEvent} e
*/
async function clickHandler(e) {
const index = Number.parseInt(e.target.dataset.index, 10);
if (isNaN(index)) return;
const options = items.map(({ id, icon, letters }, i) => {
return [i, description(id), icon, true, letters];
});
const i = await select(strings.select, options);
settings.value.quicktoolsItems[index] = i;
settings.update();
render(this);
}