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