|
|
@ -16,11 +16,9 @@
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
import { classes } from "@utils/misc";
|
|
|
|
import { LazyComponent, useAwaiter, useForceUpdater } from "@utils/react";
|
|
|
|
import { useAwaiter, useForceUpdater } from "@utils/react";
|
|
|
|
import { find, findByPropsLazy } from "@webpack";
|
|
|
|
import { findByPropsLazy } from "@webpack";
|
|
|
|
import { Forms, React, RelationshipStore, useRef, UserStore } from "@webpack/common";
|
|
|
|
import { Forms, React, RelationshipStore, UserStore } from "@webpack/common";
|
|
|
|
|
|
|
|
import type { KeyboardEvent } from "react";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { Review } from "../entities";
|
|
|
|
import { Review } from "../entities";
|
|
|
|
import { addReview, getReviews, Response, REVIEWS_PER_PAGE } from "../reviewDbApi";
|
|
|
|
import { addReview, getReviews, Response, REVIEWS_PER_PAGE } from "../reviewDbApi";
|
|
|
@ -28,7 +26,12 @@ import { settings } from "../settings";
|
|
|
|
import { authorize, cl, showToast } from "../utils";
|
|
|
|
import { authorize, cl, showToast } from "../utils";
|
|
|
|
import ReviewComponent from "./ReviewComponent";
|
|
|
|
import ReviewComponent from "./ReviewComponent";
|
|
|
|
|
|
|
|
|
|
|
|
const Classes = findByPropsLazy("inputDefault", "editable");
|
|
|
|
|
|
|
|
|
|
|
|
const Editor = findByPropsLazy("start", "end", "addMark");
|
|
|
|
|
|
|
|
const Transform = findByPropsLazy("unwrapNodes");
|
|
|
|
|
|
|
|
const InputTypes = findByPropsLazy("VOICE_CHANNEL_STATUS", "SIDEBAR");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const InputComponent = LazyComponent(() => find(m => m?.type?.render?.toString().includes("CHANNEL_TEXT_AREA).AnalyticsLocationProvider")));
|
|
|
|
|
|
|
|
|
|
|
|
interface UserProps {
|
|
|
|
interface UserProps {
|
|
|
|
discordId: string;
|
|
|
|
discordId: string;
|
|
|
@ -113,34 +116,38 @@ function ReviewList({ refetch, reviews, hideOwnReview }: { refetch(): void; revi
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function ReviewsInputComponent({ discordId, isAuthor, refetch, name }: { discordId: string, name: string; isAuthor: boolean; refetch(): void; }) {
|
|
|
|
export function ReviewsInputComponent({ discordId, isAuthor, refetch, name }: { discordId: string, name: string; isAuthor: boolean; refetch(): void; }) {
|
|
|
|
const { token } = settings.store;
|
|
|
|
const { token } = settings.store;
|
|
|
|
|
|
|
|
const editorRef = useRef<any>(null);
|
|
|
|
function onKeyPress({ key, target }: KeyboardEvent<HTMLTextAreaElement>) {
|
|
|
|
const inputType = InputTypes.FORM;
|
|
|
|
if (key === "Enter") {
|
|
|
|
inputType.disableAutoFocus = true;
|
|
|
|
addReview({
|
|
|
|
|
|
|
|
userid: discordId,
|
|
|
|
const channel = {
|
|
|
|
comment: (target as HTMLInputElement).value,
|
|
|
|
flags_: 256,
|
|
|
|
star: -1
|
|
|
|
guild_id_: null,
|
|
|
|
}).then(res => {
|
|
|
|
id: "0",
|
|
|
|
if (res?.success) {
|
|
|
|
getGuildId: () => null,
|
|
|
|
(target as HTMLInputElement).value = ""; // clear the input
|
|
|
|
isPrivate: () => true,
|
|
|
|
refetch();
|
|
|
|
isActiveThread: () => false,
|
|
|
|
} else if (res?.message) {
|
|
|
|
isArchivedLockedThread: () => false,
|
|
|
|
showToast(res.message);
|
|
|
|
isDM: () => true,
|
|
|
|
}
|
|
|
|
roles: { "0": { permissions: 0n } },
|
|
|
|
});
|
|
|
|
getRecipientId: () => "0",
|
|
|
|
}
|
|
|
|
hasFlag: () => false,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<textarea
|
|
|
|
<>
|
|
|
|
className={classes(Classes.inputDefault, "enter-comment", cl("input"))}
|
|
|
|
<div onClick={() => {
|
|
|
|
onKeyDownCapture={e => {
|
|
|
|
if (!token) {
|
|
|
|
if (e.key === "Enter") {
|
|
|
|
showToast("Opening authorization window...");
|
|
|
|
e.preventDefault(); // prevent newlines
|
|
|
|
authorize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
}}>
|
|
|
|
|
|
|
|
<InputComponent
|
|
|
|
|
|
|
|
className={cl("input")}
|
|
|
|
|
|
|
|
channel={channel}
|
|
|
|
placeholder={
|
|
|
|
placeholder={
|
|
|
|
!token
|
|
|
|
!token
|
|
|
|
? "You need to authorize to review users!"
|
|
|
|
? "You need to authorize to review users!"
|
|
|
@ -148,13 +155,43 @@ export function ReviewsInputComponent({ discordId, isAuthor, refetch, name }: {
|
|
|
|
? `Update review for @${name}`
|
|
|
|
? `Update review for @${name}`
|
|
|
|
: `Review @${name}`
|
|
|
|
: `Review @${name}`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onKeyDown={onKeyPress}
|
|
|
|
type={inputType}
|
|
|
|
onClick={() => {
|
|
|
|
disableThemedBackground={true}
|
|
|
|
if (!token) {
|
|
|
|
setEditorRef={ref => editorRef.current = ref}
|
|
|
|
showToast("Opening authorization window...");
|
|
|
|
textValue=""
|
|
|
|
authorize();
|
|
|
|
onSubmit={
|
|
|
|
|
|
|
|
async res => {
|
|
|
|
|
|
|
|
const response = await addReview({
|
|
|
|
|
|
|
|
userid: discordId,
|
|
|
|
|
|
|
|
comment: res.value,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (response?.success) {
|
|
|
|
|
|
|
|
refetch();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const slateEditor = editorRef.current.ref.current.getSlateEditor();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// clear editor
|
|
|
|
|
|
|
|
Transform.delete(slateEditor, {
|
|
|
|
|
|
|
|
at: {
|
|
|
|
|
|
|
|
anchor: Editor.start(slateEditor, []),
|
|
|
|
|
|
|
|
focus: Editor.end(slateEditor, []),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else if (response?.message) {
|
|
|
|
|
|
|
|
showToast(response.message);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// even tho we need to return this, it doesnt do anything
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
shouldClear: false,
|
|
|
|
|
|
|
|
shouldRefocus: true,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|