-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QuickCSS improvements #557
Changes from 6 commits
243ae14
a1380df
1437d03
268c0c1
609468b
a1a96b9
389d6fd
512aea3
213d62c
1abd0c4
8568845
aba34cc
1e0c9fe
fff3b61
9019fe4
95e26f4
9d68216
933d085
11c646e
12f9209
7001f41
7556fbf
c88cf1a
8f90fff
0f52589
e815318
7eb26b6
0cb58ed
21b3f09
cb06d92
4212258
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { MouseEventHandler } from "react"; | ||
|
||
export default (props: { onClick?: MouseEventHandler }): React.ReactElement => ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 24 24" | ||
fill="currentColor" | ||
onClick={props.onClick}> | ||
<path fill="currentColor" d="M19 3H5V5H7V12H5V14H11V22H13V14H19V12H17V5H19V3Z" /> | ||
</svg> | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { MouseEventHandler } from "react"; | ||
|
||
export default (props: { onClick?: MouseEventHandler }): React.ReactElement => ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not use onClick on svg's. Instead use this icon wrapped in a Clickable component. |
||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 24 24" | ||
fill="currentColor" | ||
onClick={props.onClick}> | ||
<path d="M10 5V3H5.375C4.06519 3 3 4.06519 3 5.375V18.625C3 19.936 4.06519 21 5.375 21H18.625C19.936 21 21 19.936 21 18.625V14H19V19H5V5H10Z M21 2.99902H14V4.99902H17.586L9.29297 13.292L10.707 14.706L19 6.41302V9.99902H21V2.99902Z" /> | ||
</svg> | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
export default (): React.ReactElement => ( | ||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" fill="currentColor"> | ||
import { MouseEventHandler } from "react"; | ||
|
||
export default (props: { onClick?: MouseEventHandler }): React.ReactElement => ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, use Clickable. |
||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 512 512" | ||
fill="currentColor" | ||
onClick={props.onClick}> | ||
{/* Font Awesome Pro 6.2.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. */} | ||
<path d="M495.9 166.6c3.2 8.7 .5 18.4-6.4 24.6l-43.3 39.4c1.1 8.3 1.7 16.8 1.7 25.4s-.6 17.1-1.7 25.4l43.3 39.4c6.9 6.2 9.6 15.9 6.4 24.6c-4.4 11.9-9.7 23.3-15.8 34.3l-4.7 8.1c-6.6 11-14 21.4-22.1 31.2c-5.9 7.2-15.7 9.6-24.5 6.8l-55.7-17.7c-13.4 10.3-28.2 18.9-44 25.4l-12.5 57.1c-2 9.1-9 16.3-18.2 17.8c-13.8 2.3-28 3.5-42.5 3.5s-28.7-1.2-42.5-3.5c-9.2-1.5-16.2-8.7-18.2-17.8l-12.5-57.1c-15.8-6.5-30.6-15.1-44-25.4L83.1 425.9c-8.8 2.8-18.6 .3-24.5-6.8c-8.1-9.8-15.5-20.2-22.1-31.2l-4.7-8.1c-6.1-11-11.4-22.4-15.8-34.3c-3.2-8.7-.5-18.4 6.4-24.6l43.3-39.4C64.6 273.1 64 264.6 64 256s.6-17.1 1.7-25.4L22.4 191.2c-6.9-6.2-9.6-15.9-6.4-24.6c4.4-11.9 9.7-23.3 15.8-34.3l4.7-8.1c6.6-11 14-21.4 22.1-31.2c5.9-7.2 15.7-9.6 24.5-6.8l55.7 17.7c13.4-10.3 28.2-18.9 44-25.4l12.5-57.1c2-9.1 9-16.3 18.2-17.8C227.3 1.2 241.5 0 256 0s28.7 1.2 42.5 3.5c9.2 1.5 16.2 8.7 18.2 17.8l12.5 57.1c15.8 6.5 30.6 15.1 44 25.4l55.7-17.7c8.8-2.8 18.6-.3 24.5 6.8c8.1 9.8 15.5 20.2 22.1 31.2l4.7 8.1c6.1 11 11.4 22.4 15.8 34.3zM256 336c44.2 0 80-35.8 80-80s-35.8-80-80-80s-80 35.8-80 80s35.8 80 80 80z" /> | ||
</svg> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { MouseEventHandler } from "react"; | ||
|
||
export default (props: { onClick?: MouseEventHandler }): React.ReactElement => ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 24 24" | ||
fill="currentColor" | ||
onClick={props.onClick}> | ||
<g fill="none" fillRule="evenodd"> | ||
<path | ||
fill="#f04747" | ||
d="M21.47,3.39,20.14,2.05,2.53,19.66,3.86,21l4.41-4.4,1.3-1.31,1.75-1.74,3.83-3.83Z" | ||
/> | ||
</g> | ||
<g fill="none"> | ||
<polygon | ||
points="17 11.14 16.55 11.59 14.14 14 19 14 19 12 17 12 17 11.14" | ||
fill="currentColor" | ||
/> | ||
<polygon points="16.91 3 5 3 5 5 7 5 7 12 5 12 5 14 5.91 14 16.91 3" fill="currentColor" /> | ||
<polygon points="12.72 15.42 11 17.14 11 22 13 22 13 15.14 12.72 15.42" fill="currentColor" /> | ||
</g> | ||
</svg> | ||
); |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,13 +1,19 @@ | ||||||
import { React, toast } from "@common"; | ||||||
import { React, flux, toast } from "@common"; | ||||||
import { Messages } from "@common/i18n"; | ||||||
import { EditorView, basicSetup } from "codemirror"; | ||||||
import { EditorState } from "@codemirror/state"; | ||||||
import { css } from "@codemirror/lang-css"; | ||||||
import { githubDark, githubLight } from "./codemirror-github"; | ||||||
import { webpack } from "@replugged"; | ||||||
import { Button, Divider, Flex, Text } from "@components"; | ||||||
import { Button, ButtonItem, Divider, Flex, Text, Tooltip } from "@components"; | ||||||
import "./QuickCSS.css"; | ||||||
import { generalSettings } from "./General"; | ||||||
import { ReactComponent } from "src/types"; | ||||||
import { Store } from "@common/flux"; | ||||||
import Settings from "../icons/Settings"; | ||||||
import Popout from "../icons/Popout"; | ||||||
import Unpin from "../icons/Unpin"; | ||||||
import Pin from "../icons/Pin"; | ||||||
|
||||||
interface UseCodeMirrorOptions { | ||||||
value?: string; | ||||||
|
@@ -22,6 +28,38 @@ type ThemeModule = { | |||||
removeChangeListener: (listener: () => unknown) => unknown; | ||||||
}; | ||||||
|
||||||
const PopoutModule = await webpack.waitForModule( | ||||||
webpack.filters.bySource('type:"POPOUT_WINDOW_OPEN"'), | ||||||
); | ||||||
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All these comments to disable the rules are useless. Instead use the |
||||||
const openPopout = webpack.getFunctionBySource(PopoutModule, "POPOUT_WINDOW_OPEN") as ( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type generics are a thing with these webpack functions. Use them. |
||||||
key: string, | ||||||
render: ReactComponent<unknown>, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I completely deleted the |
||||||
features: Record<string, string>, | ||||||
) => void; | ||||||
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style | ||||||
const closePopout = webpack.getFunctionBySource(PopoutModule, "POPOUT_WINDOW_CLOSE") as ( | ||||||
key: string, | ||||||
) => void; | ||||||
|
||||||
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style | ||||||
const setAlwaysOnTop = webpack.getFunctionBySource( | ||||||
PopoutModule, | ||||||
"POPOUT_WINDOW_SET_ALWAYS_ON_TOP", | ||||||
) as (key: string, alwaysOnTop: boolean) => void; | ||||||
|
||||||
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style | ||||||
const PopoutWindowStore = webpack.getByStoreName("PopoutWindowStore") as Store & { | ||||||
getWindow: (key: string) => Window; | ||||||
getWindowOpen: (key: string) => boolean; | ||||||
getIsAlwaysOnTop: (key: string) => boolean; | ||||||
}; | ||||||
|
||||||
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style | ||||||
const DnDProvider = webpack.getBySource( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be precise, do not confuse the two components, which are different (DragAndDropProvider vs PopoutWindow)
Suggested change
|
||||||
".EMBEDDED_ACTIVITIES_ARE_YOU_SURE_WANT_TO_LEAVE", | ||||||
) as ReactComponent<unknown>; | ||||||
|
||||||
function useTheme(): "light" | "dark" { | ||||||
const [theme, setTheme] = React.useState<"light" | "dark">("dark"); | ||||||
|
||||||
|
@@ -110,7 +148,7 @@ function useCodeMirror({ value: initialValueParam, onChange, container }: UseCod | |||||
return { value, setValue: customSetValue }; | ||||||
} | ||||||
|
||||||
export const QuickCSS = (): React.ReactElement => { | ||||||
const QuickCSS = (props: { popout: boolean } & Record<string, boolean>): React.ReactElement => { | ||||||
const ref = React.useRef<HTMLDivElement>(null); | ||||||
const { value, setValue } = useCodeMirror({ | ||||||
container: ref.current, | ||||||
|
@@ -170,24 +208,109 @@ export const QuickCSS = (): React.ReactElement => { | |||||
if (autoApply) setReloadTimer(setTimeout(reload, 500)); | ||||||
}, [value]); | ||||||
|
||||||
if (props.popout) { | ||||||
React.useEffect(() => { | ||||||
const window = PopoutWindowStore?.getWindow("DISCORD_REPLUGGED_QUICKCSS"); | ||||||
|
||||||
let el = window.document.createElement("link"); | ||||||
el.rel = "stylesheet"; | ||||||
el.href = `replugged://renderer.css?t=${Date.now()}`; | ||||||
window.document.head.appendChild(el); | ||||||
}, []); | ||||||
} | ||||||
|
||||||
const [alwaysOnTop, setAlwaysOnTop_] = React.useState(props.popoutOnTop); | ||||||
|
||||||
return ( | ||||||
<> | ||||||
<Flex justify={Flex.Justify.BETWEEN} align={Flex.Align.START}> | ||||||
<Text.H2>{Messages.REPLUGGED_QUICKCSS}</Text.H2> | ||||||
<div style={{ display: "flex" }}> | ||||||
{autoApply ? null : ( | ||||||
<Button onClick={reloadAndToast}>{Messages.REPLUGGED_QUICKCSS_CHANGES_APPLY}</Button> | ||||||
)} | ||||||
<Button | ||||||
onClick={() => window.RepluggedNative.quickCSS.openFolder()} | ||||||
color={Button.Colors.PRIMARY} | ||||||
look={Button.Looks.LINK}> | ||||||
{Messages.REPLUGGED_QUICKCSS_FOLDER_OPEN} | ||||||
</Button> | ||||||
{!props.popout ? ( | ||||||
<> | ||||||
<Flex justify={Flex.Justify.BETWEEN} align={Flex.Align.START}> | ||||||
<Text.H2>{Messages.REPLUGGED_QUICKCSS}</Text.H2> | ||||||
<div style={{ display: "flex" }}> | ||||||
{autoApply ? null : ( | ||||||
<Button onClick={reloadAndToast}> | ||||||
{Messages.REPLUGGED_QUICKCSS_CHANGES_APPLY} | ||||||
</Button> | ||||||
)} | ||||||
<Button | ||||||
onClick={() => window.RepluggedNative.quickCSS.openFolder()} | ||||||
color={Button.Colors.PRIMARY} | ||||||
look={Button.Looks.LINK}> | ||||||
{Messages.REPLUGGED_QUICKCSS_FOLDER_OPEN} | ||||||
</Button> | ||||||
</div> | ||||||
</Flex> | ||||||
<Divider style={{ margin: "20px 0px" }} /> | ||||||
</> | ||||||
) : null} | ||||||
|
||||||
{!props.popout && props.isPopoutOpen ? ( | ||||||
<ButtonItem | ||||||
button="Close Popout" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i18n. You can use POPOUT_RETURN. |
||||||
onClick={() => { | ||||||
closePopout("DISCORD_REPLUGGED_QUICKCSS"); | ||||||
}}> | ||||||
{Messages.REPLUGGED_QUICKCSS_POPPED_OUT} | ||||||
</ButtonItem> | ||||||
) : ( | ||||||
<div id="replugged-quickcss-wrapper" data-popout={props.popout}> | ||||||
<div className="replugged-quickcss-header"> | ||||||
<Tooltip text={Messages.SETTINGS}> | ||||||
<Settings /> | ||||||
</Tooltip> | ||||||
|
||||||
{props.popout ? ( | ||||||
<Tooltip | ||||||
text={alwaysOnTop ? Messages.POPOUT_REMOVE_FROM_TOP : Messages.POPOUT_STAY_ON_TOP}> | ||||||
{alwaysOnTop ? ( | ||||||
<Unpin | ||||||
onClick={() => { | ||||||
setAlwaysOnTop("DISCORD_REPLUGGED_QUICKCSS", false); | ||||||
setAlwaysOnTop_(false); | ||||||
}} | ||||||
/> | ||||||
) : ( | ||||||
<Pin | ||||||
onClick={() => { | ||||||
setAlwaysOnTop("DISCORD_REPLUGGED_QUICKCSS", true); | ||||||
setAlwaysOnTop_(true); | ||||||
}} | ||||||
/> | ||||||
)} | ||||||
</Tooltip> | ||||||
) : ( | ||||||
<Tooltip text={Messages.POPOUT_PLAYER}> | ||||||
<Popout | ||||||
onClick={() => { | ||||||
openPopout( | ||||||
"DISCORD_REPLUGGED_QUICKCSS", | ||||||
() => ( | ||||||
<DnDProvider windowKey="DISCORD_REPLUGGED_QUICKCSS"> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass a |
||||||
<QuickCSS popout={true}></QuickCSS> | ||||||
</DnDProvider> | ||||||
), | ||||||
{}, | ||||||
); | ||||||
}} | ||||||
/> | ||||||
</Tooltip> | ||||||
)} | ||||||
</div> | ||||||
<div ref={ref}></div> | ||||||
</div> | ||||||
</Flex> | ||||||
<Divider style={{ margin: "20px 0px" }} /> | ||||||
<div ref={ref} id="replugged-quickcss-wrapper" /> | ||||||
)} | ||||||
</> | ||||||
); | ||||||
}; | ||||||
|
||||||
export const ConnectedQuickCSS = flux.connectStores< | ||||||
{ popout: boolean }, | ||||||
{ popout: boolean; isPopoutOpen: boolean } | ||||||
>([PopoutWindowStore], (props) => { | ||||||
return { | ||||||
isPopoutOpen: PopoutWindowStore.getWindowOpen("DISCORD_REPLUGGED_QUICKCSS"), | ||||||
popoutOnTop: PopoutWindowStore.getIsAlwaysOnTop("DISCORD_REPLUGGED_QUICKCSS"), | ||||||
...props, | ||||||
}; | ||||||
})(QuickCSS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a component (StayOnTopButton, id 631443) with the icon and all the functionality already done.