diff --git a/Website/src/activitys/SubmitModuleActivity.tsx b/Website/src/activitys/SubmitModuleActivity.tsx index e9c1ae01..3e728455 100644 --- a/Website/src/activitys/SubmitModuleActivity.tsx +++ b/Website/src/activitys/SubmitModuleActivity.tsx @@ -1,20 +1,5 @@ import React from "react"; -import { - TextField, - Autocomplete, - Card, - Chip, - Stack, - Avatar, - Typography, - CardContent, - FormControl, - InputLabel, - MenuItem, - Select, - Divider, - Box, -} from "@mui/material"; +import { TextField, Autocomplete, Chip, Stack, Avatar, Typography, Divider } from "@mui/material"; import { Toolbar } from "@Components/onsenui/Toolbar"; import { Page } from "@Components/onsenui/Page"; import { useCategories } from "@Hooks/useCategories"; @@ -24,18 +9,23 @@ import { useTheme } from "@Hooks/useTheme"; import { MMRL } from "@Components/icons/MMRL"; import { MRepo } from "@Components/icons/MRepo"; import { useNativeFileStorage } from "@Hooks/useNativeFileStorage"; -import hljs from "highlight.js"; import { licenseTypes } from "@Util/licenseTypes"; import { CodeBlock } from "@Components/CodeBlock"; import { useModFS } from "@Hooks/useModFS"; +import { path } from "@Util/path"; +import { en_antifeatures } from "./../locales/antifeatures/en"; -interface FormTypes { +interface FormTypesTrack { id: string; enable: boolean; verified: boolean; - license: string; update_to: string; source: string; + antifeatures: string[]; +} + +interface FormTypesRepo { + license: string; support: string; donate: string; cover: string; @@ -43,17 +33,20 @@ interface FormTypes { categories: string[]; require: string[]; screenshots: string[]; - antifeatures: string[]; readme: string; } -const INITIAL_FORM: FormTypes = { +const INITIAL_TRACK_FORM: FormTypesTrack = { id: "", enable: true, verified: false, - license: "", update_to: "", source: "", + antifeatures: [], +}; + +const INITIAL_COM_REPO_FORM: FormTypesRepo = { + license: "", support: "", donate: "", cover: "", @@ -61,23 +54,10 @@ const INITIAL_FORM: FormTypes = { categories: [], require: [], screenshots: [], - antifeatures: [], readme: "", }; -const antifeatures = [ - "Ads", - "Tracking", - "Non-Free Network Services", - "Non-Free Addons", - "Non-Free Dependencies", - "NSFW", - "Upstream Non-Free", - "NonßFree Assets", - "Known Vulnerability", - "Disabled Algorithm", - "No Source Since", -]; +const antifeatures = en_antifeatures.map((af) => af.id); const SupportedApp = React.memo<{ mmrl?: boolean; mrepo?: boolean }>((props) => { return ( @@ -110,8 +90,6 @@ const SubmitModuleActivity = () => { const { theme } = useTheme(); const { modFS } = useModFS(); - const ref = React.useRef(null); - const renderToolbar = () => { return ( @@ -122,88 +100,103 @@ const SubmitModuleActivity = () => { ); }; - const [formData, setFormData] = useNativeFileStorage(`${modFS("ADB")}/mmrl/submit-form.json`, INITIAL_FORM, { loader: "json" }); + const [trackFormData, setTrackFormData] = useNativeFileStorage( + path.resolve(modFS("MMRLFOL"), "submit-form-track.json"), + INITIAL_TRACK_FORM, + { + loader: "json", + } + ); + const [repoFormData, setRepoFormData] = useNativeFileStorage( + path.resolve(modFS("MMRLFOL"), "submit-form-repo.json"), + INITIAL_COM_REPO_FORM, + { + loader: "json", + } + ); - const handleChange = (e: React.ChangeEvent) => { + const handleTrackChange = (e: React.ChangeEvent) => { const { name, value } = e.target; - setFormData((prevState) => ({ ...prevState, [name]: value })); + setTrackFormData((prevState) => ({ ...prevState, [name]: value })); }; - const handleLicenseError = React.useMemo(() => !licenseTypes.includes(formData.license), [formData.license]); + const handleRepoChange = (e: React.ChangeEvent) => { + const { name, value } = e.target; - React.useEffect(() => { - if (ref.current) { - ref.current.querySelectorAll("pre code").forEach((block) => { - block.removeAttribute("data-highlighted"); - hljs.highlightBlock(block); - }); - } - }, [formData]); + setRepoFormData((prevState) => ({ ...prevState, [name]: value })); + }; + + const isInvalidLicense = React.useMemo(() => !licenseTypes.includes(repoFormData.license), [repoFormData.license]); return ( - {JSON.stringify(formData, null, 4)} + {JSON.stringify( + { + "track.json": trackFormData, + "common/repo.json": repoFormData, + }, + null, + 2 + )} - - - - Available in MMRL - - - Available in MRepo - - - - } - /> + + track.json + + + } + value={trackFormData.source} + onChange={handleTrackChange} /> } /> + { + setTrackFormData((prevState) => ({ ...prevState, antifeatures: value })); + }} + filterSelectedOptions + disableCloseOnSelect + renderInput={(params) => } + /> + + + common/repo.json + + } + value={repoFormData.license} + onChange={handleRepoChange} /> { fullWidth label="Support URL" name="support" - value={formData.support} - onChange={handleChange} - helperText={} + value={repoFormData.support} + onChange={handleRepoChange} /> { fullWidth label="Donate URL" name="donate" - value={formData.donate} - onChange={handleChange} - helperText={} + value={repoFormData.donate} + onChange={handleRepoChange} /> { - setFormData((prevState) => ({ ...prevState, categories: value })); + setRepoFormData((prevState) => ({ ...prevState, categories: value })); }} disableCloseOnSelect filterSelectedOptions - renderInput={(params) => } />} - /> - - { - setFormData((prevState) => ({ ...prevState, antifeatures: value })); - }} - filterSelectedOptions - disableCloseOnSelect - renderInput={(params) => } />} + renderInput={(params) => } /> { fullWidth label="Module Cover" name="cover" - value={formData.cover} - onChange={handleChange} - helperText={} + value={repoFormData.cover} + onChange={handleRepoChange} /> { fullWidth label="Module Icon" name="icon" - value={formData.icon} - onChange={handleChange} - helperText={} + value={repoFormData.icon} + onChange={handleRepoChange} /> { fullWidth label="Raw README.md URL" name="readme" - value={formData.readme} - onChange={handleChange} - helperText={} + value={repoFormData.readme} + onChange={handleRepoChange} /> { }, }} multiple - value={formData.screenshots} + value={repoFormData.screenshots} onChange={(e, value) => { - setFormData((prevState) => ({ ...prevState, screenshots: value })); + setRepoFormData((prevState) => ({ ...prevState, screenshots: value })); }} options={[]} freeSolo @@ -309,9 +284,7 @@ const SubmitModuleActivity = () => { ))} )} - renderInput={(params) => ( - } /> - )} + renderInput={(params) => } /> { }, }} multiple - value={formData.require} + value={repoFormData.require} onChange={(e, value) => { - setFormData((prevState) => ({ ...prevState, require: value })); + setRepoFormData((prevState) => ({ ...prevState, require: value })); }} options={[]} freeSolo @@ -341,9 +314,7 @@ const SubmitModuleActivity = () => { ))} )} - renderInput={(params) => ( - } /> - )} + renderInput={(params) => } />