-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathExploreModuleFragment.tsx
183 lines (169 loc) · 5.06 KB
/
ExploreModuleFragment.tsx
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import { Component, LegacyRef } from "react";
import { Button, SearchInput, ProgressCircular } from "react-onsenui";
import axios from "axios";
import { toast } from "react-toastify";
import ExploreModule from "@Components/ExploreModule";
import SharedPreferences from "@Native/SharedPreferences";
import { PushProps } from "@Activitys/MainActivity";
import { SearchRounded } from "@mui/icons-material";
import { os } from "@Native/os";
import ons from "onsenui";
interface Props {
pushPage(...arg: any): PushProps;
}
interface States {
modulesIndex: any[any];
currentSerachText: string;
search: string;
moduleOptions: any[any];
loading: boolean;
}
class ExploreModuleFragment extends Component<Props, States> {
private searchBar: LegacyRef<SearchInput> | undefined;
private prefManager: SharedPreferences;
public constructor(props: Props | Readonly<Props>) {
super(props);
this.state = {
modulesIndex: [],
currentSerachText: "",
search: "",
moduleOptions: {},
loading: true,
};
this.prefManager = new SharedPreferences();
}
public componentDidMount = () => {
const moduels = os.getSchemeParam("module");
if (moduels != (null || undefined || "")) {
ons.notification.toast("Please wait 2 seconds after the loading screen is gone", { timeout: 2000, animation: "fall" });
}
setTimeout(() => {
this.setState({ loading: false });
}, 2000);
axios
.get(this.prefManager.getString("repo", "https://raw.githubusercontent.com/Magisk-Modules-Alt-Repo/json/main/modules.json"))
.then((response) => {
const modules = response.data.modules;
this.setState({
modulesIndex: modules,
});
})
.catch((error) => {
this.setState({
modulesIndex: [],
});
})
.then(() => {
// always executed
});
axios.get("https://repo.dergoogler.com/moduleOptions.json").then((response) => {
this.setState({
moduleOptions: response.data,
});
});
};
public componentDidCatch = () => {};
private filter = (e: any) => {
this.setState({ currentSerachText: e.target.value.toLowerCase() });
};
private triggerSearch = () => {
const { currentSerachText } = this.state;
this.setState({ search: currentSerachText });
};
public render = () => {
const { search, loading } = this.state;
return (
<>
<div
style={{
textAlign: "center",
display: "flex",
justifyContent: "center",
padding: "0px",
paddingBottom: "0px",
flexDirection: "column",
}}
>
<div
style={{
textAlign: "center",
display: "inline-flex",
justifyContent: "center",
padding: "8px 8px 4px",
}}
>
<SearchInput
placeholder={"Search modules"}
ref={this.searchBar}
style={{
borderRadius: "8px",
width: "100%",
marginRight: "4px",
}}
onChange={this.filter}
/>
<Button
onClick={this.triggerSearch}
style={{
textAlign: "center",
display: "flex",
justifyContent: "center",
marginLeft: "4px",
borderRadius: "8px",
}}
>
<div
style={{
textAlign: "center",
height: "100%",
width: "100%",
display: "flex",
flexDirection: "column",
justifyContent: "center",
alignItems: "center",
}}
>
<SearchRounded sx={{ color: "white" }} />
</div>
</Button>
</div>
<module-container
style={{
paddingBottom: "4px",
}}
>
{loading ? (
<ProgressCircular
indeterminate
style={{
position: "absolute",
left: "50%",
top: "50%",
WebkitTransform: "translate(-50%, -50%)",
transform: "translate(-50%, -50%)",
}}
/>
) : (
this.state.modulesIndex.map((item: any) => {
return (
<ExploreModule
key={item.id}
getId={item.id}
propsUrl={item.prop_url}
notesUrl={item.notes_url}
downloadUrl={item.zip_url}
pushPage={this.props.pushPage}
searchState={search}
moduleOptions={this.state.moduleOptions}
last_update={item.last_update}
/>
);
})
)}
</module-container>
</div>
</>
);
};
}
export default ExploreModuleFragment;