ReviewDB fixes
This commit is contained in:
parent
8bd54173db
commit
a171b35e97
4 changed files with 24 additions and 24 deletions
|
@ -14,7 +14,7 @@ import { ReviewDBAuth } from "./entities";
|
|||
|
||||
const DATA_STORE_KEY = "rdb-auth";
|
||||
|
||||
const OAuth = findByPropsLazy("OAuth2AuthorizeModal");
|
||||
const { OAuth2AuthorizeModal } = findByPropsLazy("OAuth2AuthorizeModal");
|
||||
|
||||
export let Auth: ReviewDBAuth = {};
|
||||
|
||||
|
@ -46,7 +46,7 @@ export async function updateAuth(newAuth: ReviewDBAuth) {
|
|||
|
||||
export function authorize(callback?: any) {
|
||||
openModal(props =>
|
||||
<OAuth.OAuth2AuthorizeModal
|
||||
<OAuth2AuthorizeModal
|
||||
{...props}
|
||||
scopes={["identify"]}
|
||||
responseType="code"
|
||||
|
@ -64,7 +64,7 @@ export function authorize(callback?: any) {
|
|||
const { token, success } = await res.json();
|
||||
if (success) {
|
||||
updateAuth({ token });
|
||||
showToast("Successfully logged in!");
|
||||
showToast("Successfully logged in!", Toasts.Type.SUCCESS);
|
||||
callback?.();
|
||||
} else if (res.status === 1) {
|
||||
showToast("An Error occurred while logging in.", Toasts.Type.FAILURE);
|
||||
|
|
|
@ -32,7 +32,7 @@ import { BlockButton, DeleteButton, ReportButton } from "./MessageButton";
|
|||
import ReviewBadge from "./ReviewBadge";
|
||||
|
||||
export default LazyComponent(() => {
|
||||
// this is terrible, blame ven
|
||||
// this is terrible, blame mantika
|
||||
const p = filters.byProps;
|
||||
const [
|
||||
{ cozyMessage, buttons, message, buttonsInner, groupStart },
|
||||
|
|
|
@ -28,8 +28,8 @@ import { cl } from "../utils";
|
|||
import ReviewComponent from "./ReviewComponent";
|
||||
|
||||
|
||||
const Slate = findByPropsLazy("Editor", "Transforms");
|
||||
const InputTypes = findByPropsLazy("ChatInputTypes");
|
||||
const { Editor, Transforms } = findByPropsLazy("Editor", "Transforms");
|
||||
const { ChatInputTypes } = findByPropsLazy("ChatInputTypes");
|
||||
|
||||
const InputComponent = LazyComponent(() => find(m => m.default?.type?.render?.toString().includes("default.CHANNEL_TEXT_AREA")).default);
|
||||
|
||||
|
@ -122,7 +122,7 @@ function ReviewList({ refetch, reviews, hideOwnReview, profileId }: { refetch():
|
|||
export function ReviewsInputComponent({ discordId, isAuthor, refetch, name }: { discordId: string, name: string; isAuthor: boolean; refetch(): void; }) {
|
||||
const { token } = Auth;
|
||||
const editorRef = useRef<any>(null);
|
||||
const inputType = InputTypes.ChatInputTypes.FORM;
|
||||
const inputType = ChatInputTypes.FORM;
|
||||
inputType.disableAutoFocus = true;
|
||||
|
||||
const channel = {
|
||||
|
@ -172,10 +172,9 @@ export function ReviewsInputComponent({ discordId, isAuthor, refetch, name }: {
|
|||
refetch();
|
||||
|
||||
const slateEditor = editorRef.current.ref.current.getSlateEditor();
|
||||
const { Editor, Transform } = Slate;
|
||||
|
||||
// clear editor
|
||||
Transform.delete(slateEditor, {
|
||||
Transforms.delete(slateEditor, {
|
||||
at: {
|
||||
anchor: Editor.start(slateEditor, []),
|
||||
focus: Editor.end(slateEditor, []),
|
||||
|
|
|
@ -19,10 +19,10 @@
|
|||
import { showToast, Toasts } from "@webpack/common";
|
||||
|
||||
import { Auth, authorize, getToken, updateAuth } from "./auth";
|
||||
import { Review, ReviewDBCurrentUser, ReviewDBUser } from "./entities";
|
||||
import { Review, ReviewDBCurrentUser, ReviewDBUser, ReviewType } from "./entities";
|
||||
import { settings } from "./settings";
|
||||
|
||||
const API_URL = "https://manti.vendicated.dev";
|
||||
const API_URL = "https://manti.vendicated.dev/api/reviewdb";
|
||||
|
||||
export const REVIEWS_PER_PAGE = 50;
|
||||
|
||||
|
@ -45,13 +45,13 @@ export async function getReviews(id: string, offset = 0): Promise<Response> {
|
|||
flags: String(flags),
|
||||
offset: String(offset)
|
||||
});
|
||||
const req = await fetch(`${API_URL}/api/reviewdb/users/${id}/reviews?${params}`);
|
||||
const req = await fetch(`${API_URL}/users/${id}/reviews?${params}`);
|
||||
|
||||
const res = (req.status === 200)
|
||||
? await req.json() as Response
|
||||
: {
|
||||
success: false,
|
||||
message: "An Error occured while fetching reviews. Please try again later.",
|
||||
message: req.status === 429 ? "You are sending requests too fast. Wait a few seconds and try again." : "An Error occured while fetching reviews. Please try again later.",
|
||||
reviews: [],
|
||||
updated: false,
|
||||
hasNextPage: false,
|
||||
|
@ -65,14 +65,15 @@ export async function getReviews(id: string, offset = 0): Promise<Response> {
|
|||
reviews: [
|
||||
{
|
||||
id: 0,
|
||||
comment: "An Error occured while fetching reviews. Please try again later.",
|
||||
comment: res.message,
|
||||
star: 0,
|
||||
timestamp: 0,
|
||||
type: ReviewType.System,
|
||||
sender: {
|
||||
id: 0,
|
||||
username: "Error",
|
||||
profilePhoto: "https://cdn.discordapp.com/attachments/1045394533384462377/1084900598035513447/646808599204593683.png?size=128",
|
||||
discordID: "0",
|
||||
username: "ReviewDB",
|
||||
profilePhoto: "https://cdn.discordapp.com/avatars/1134864775000629298/3f87ad315b32ee464d84f1270c8d1b37.png?size=256&format=webp&quality=lossless",
|
||||
discordID: "1134864775000629298",
|
||||
badges: []
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +93,7 @@ export async function addReview(review: any): Promise<Response | null> {
|
|||
return null;
|
||||
}
|
||||
|
||||
return fetch(API_URL + `/api/reviewdb/users/${review.userid}/reviews`, {
|
||||
return fetch(API_URL + `/users/${review.userid}/reviews`, {
|
||||
method: "PUT",
|
||||
body: JSON.stringify(review),
|
||||
headers: {
|
||||
|
@ -107,7 +108,7 @@ export async function addReview(review: any): Promise<Response | null> {
|
|||
}
|
||||
|
||||
export async function deleteReview(id: number): Promise<Response> {
|
||||
return fetch(API_URL + `/api/reviewdb/users/${id}/reviews`, {
|
||||
return fetch(API_URL + `/users/${id}/reviews`, {
|
||||
method: "DELETE",
|
||||
headers: new Headers({
|
||||
"Content-Type": "application/json",
|
||||
|
@ -121,7 +122,7 @@ export async function deleteReview(id: number): Promise<Response> {
|
|||
}
|
||||
|
||||
export async function reportReview(id: number) {
|
||||
const res = await fetch(API_URL + "/api/reviewdb/reports", {
|
||||
const res = await fetch(API_URL + "/reports", {
|
||||
method: "PUT",
|
||||
headers: new Headers({
|
||||
"Content-Type": "application/json",
|
||||
|
@ -137,7 +138,7 @@ export async function reportReview(id: number) {
|
|||
}
|
||||
|
||||
async function patchBlock(action: "block" | "unblock", userId: string) {
|
||||
const res = await fetch(API_URL + "/api/reviewdb/blocks", {
|
||||
const res = await fetch(API_URL + "/blocks", {
|
||||
method: "PATCH",
|
||||
headers: new Headers({
|
||||
"Content-Type": "application/json",
|
||||
|
@ -168,7 +169,7 @@ export const blockUser = (userId: string) => patchBlock("block", userId);
|
|||
export const unblockUser = (userId: string) => patchBlock("unblock", userId);
|
||||
|
||||
export async function fetchBlocks(): Promise<ReviewDBUser[]> {
|
||||
const res = await fetch(API_URL + "/api/reviewdb/blocks", {
|
||||
const res = await fetch(API_URL + "/blocks", {
|
||||
method: "GET",
|
||||
headers: new Headers({
|
||||
Accept: "application/json",
|
||||
|
@ -181,14 +182,14 @@ export async function fetchBlocks(): Promise<ReviewDBUser[]> {
|
|||
}
|
||||
|
||||
export function getCurrentUserInfo(token: string): Promise<ReviewDBCurrentUser> {
|
||||
return fetch(API_URL + "/api/reviewdb/users", {
|
||||
return fetch(API_URL + "/users", {
|
||||
body: JSON.stringify({ token }),
|
||||
method: "POST",
|
||||
}).then(r => r.json());
|
||||
}
|
||||
|
||||
export async function readNotification(id: number) {
|
||||
return fetch(API_URL + `/api/reviewdb/notifications?id=${id}`, {
|
||||
return fetch(API_URL + `/notifications?id=${id}`, {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Authorization": await getToken() || "",
|
||||
|
|
Loading…
Reference in a new issue