generated from replugged-org/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Magix <[email protected]>
- Loading branch information
1 parent
12d4d6b
commit fbf8b88
Showing
7 changed files
with
99 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,38 @@ | ||
import { Injector, Logger, webpack } from "replugged"; | ||
import { Injector, Logger, settings } from "replugged"; | ||
import "./style.css" | ||
|
||
const inject = new Injector(); | ||
const logger = Logger.plugin("Clips Enhanced"); | ||
|
||
interface Option { | ||
export interface Option { | ||
value: number; | ||
label: string; | ||
} | ||
|
||
export async function start(): Promise<void> { | ||
export interface Options { | ||
clipOptions: Option[]; | ||
} | ||
|
||
export const setting = await settings.init("dev.wolfplugs.ClipsEnhanced", { | ||
clipOptions: [ | ||
{ | ||
value: 300e3, | ||
label: "5 minutes", | ||
}, | ||
], | ||
}); | ||
|
||
export function start(): Promise<void> { | ||
logger.log("Enabled custom clip settings."); | ||
return new Promise(() => {}); | ||
} | ||
|
||
export function stop(): void { | ||
inject.uninjectAll(); | ||
} | ||
|
||
export function customOptions(): Option[] { | ||
return [ | ||
{ | ||
value: 300e3, | ||
label: "5 minutes" | ||
} | ||
]; | ||
return setting.get("clipOptions"); | ||
} | ||
|
||
export { Settings } from "./settings"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,70 @@ | ||
import { common, components, settings } from "replugged"; | ||
import { common, components, settings, types } from "replugged"; | ||
import { ReactElement } from "./type"; | ||
import { setting } from "."; | ||
|
||
const { React } = common; | ||
const { Modal: { ModalRoot, ModalHeader, ModalCloseButton, ModalFooter, ModalContent }, Text, TextInput } = components; | ||
const { Modal: { ModalRoot, ModalHeader, ModalCloseButton, ModalFooter, ModalContent }, Text, TextInput, Select, Button } = components; | ||
|
||
function parseTime(time: string, unit: string) { | ||
function parseTime(time: string, unit: string): number { | ||
const rawTime = parseInt(time); | ||
switch (unit) { | ||
case "seconds": | ||
case "Seconds": | ||
return rawTime * 1e3; | ||
case "minutes": | ||
case "Minutes": | ||
return rawTime * 60e3; | ||
case "hours": | ||
case "Hours": | ||
return rawTime * 3600e3; | ||
default: | ||
return rawTime; | ||
} | ||
} | ||
|
||
function setClipTime(time: string, unit: string): void { | ||
|
||
} | ||
|
||
export default (props) => { | ||
const Units = ["Seconds", "Minutes", "Hours"]; | ||
|
||
export const Settings = (): ReactElement => { | ||
const [time, setTime] = React.useState<string>(); | ||
const [unit, setUnit] = React.useState<string>(); | ||
|
||
|
||
const formatedTime = React.useCallback(() => { | ||
const time5 = parseTime(time, unit); | ||
setting.set("clipOptions", [ | ||
{ value: time5, | ||
label: `${time} ${unit}` | ||
} | ||
]); | ||
}, [time, unit]) | ||
|
||
return ( | ||
<ModalRoot {...props}> | ||
<ModalHeader> | ||
<div> | ||
<ModalHeader className="title-header"> | ||
<Text tag="h3">Set Time</Text> | ||
</ModalHeader> | ||
<ModalContent> | ||
<TextInput | ||
value={time} | ||
placeholder="Time" | ||
onChange={(value) => setTime(value)} | ||
style={{ marginBottom: "10pc"}} | ||
onChange={(value: string) => setTime(value)} | ||
style={{ marginBottom: "10pc" }} | ||
/> | ||
|
||
|
||
<ModalContent/> | ||
<ModalRoot/> | ||
<Select | ||
options={ | ||
Units.map((unit) => ({ | ||
label: unit, | ||
value: unit, | ||
})) | ||
} | ||
isSelected={(value: string) => value === unit} | ||
select={(value: string) => setUnit(value)} | ||
serialize={(value: string) => value} | ||
/> | ||
</ModalContent> | ||
<ModalFooter> | ||
<Button | ||
onClick={() => { | ||
formatedTime(); | ||
}} | ||
/> | ||
</ModalFooter> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.title-header { | ||
margin-bottom: 10px; | ||
padding: 16px 16px 10px 16px; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { ReactElement } from "react" |