aboutsummaryrefslogtreecommitdiff
path: root/features/settings/helpDataLoader.js
diff options
context:
space:
mode:
authorSoopyboo32 <49228220+Soopyboo32@users.noreply.github.com>2022-04-03 00:05:04 +0800
committerSoopyboo32 <49228220+Soopyboo32@users.noreply.github.com>2022-04-03 00:05:04 +0800
commit7efa7599053cc8da203286d2beaeac737b2325f1 (patch)
tree70f50385e4cd6bc7749d611cfab241714663fbea /features/settings/helpDataLoader.js
parent4411297dc00f5fa33864530756fbeeaf617bb2c7 (diff)
downloadSoopyV2-7efa7599053cc8da203286d2beaeac737b2325f1.tar.gz
SoopyV2-7efa7599053cc8da203286d2beaeac737b2325f1.tar.bz2
SoopyV2-7efa7599053cc8da203286d2beaeac737b2325f1.zip
asd
Diffstat (limited to 'features/settings/helpDataLoader.js')
-rw-r--r--features/settings/helpDataLoader.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/features/settings/helpDataLoader.js b/features/settings/helpDataLoader.js
new file mode 100644
index 0000000..aadbd93
--- /dev/null
+++ b/features/settings/helpDataLoader.js
@@ -0,0 +1,46 @@
+import { fetch } from "../../utils/networkUtils";
+
+class HelpDataLoader {
+ constructor() {
+ this.availableHelpData = {}
+ this.dataCach = {}
+
+ fetch("http://soopymc.my.to/api/soopyv2/settingshelpoptions.json").json(data=>{
+ Object.keys(data).forEach(category=>{
+ this.availableHelpData[category] = new Set(data[category])
+ });
+ })
+ }
+
+ hasData(category, id){
+ return this.availableHelpData[category] && this.availableHelpData[category].has(id)
+ }
+
+ getData(category, id, callback){
+ if(!this.hasData(category, id)){
+ callback("")
+ return
+ }
+
+ if(this.dataCach[category] && this.dataCach[category][id]){
+ callback(this.dataCach[category][id])
+ return
+ }
+
+ fetch("http://soopymc.my.to/api/soopyv2/settingshelp/" + category + "/" + id).text(data=>{
+ if(!this.dataCach[category]){
+ this.dataCach[category] = {}
+ }
+
+ this.dataCach[category][id] = data
+
+ callback(data)
+ })
+ }
+}
+
+if(!global.helpDataLoader){
+ global.helpDataLoader = new HelpDataLoader();
+}
+
+export default global.helpDataLoader; \ No newline at end of file