refactor: reomve unused hooks

This commit is contained in:
Aaryan Khandelwal 2024-05-08 23:02:11 +05:30
parent 06c42d5669
commit 9a1bfe4169
4 changed files with 0 additions and 184 deletions

View File

@ -54,14 +54,9 @@ export const CURRENT_USER = "CURRENT_USER";
export const USER_WORKSPACE_INVITATIONS = "USER_WORKSPACE_INVITATIONS";
export const USER_WORKSPACES = "USER_WORKSPACES";
export const WORKSPACE_DETAILS = (workspaceSlug: string) => `WORKSPACE_DETAILS_${workspaceSlug.toUpperCase()}`;
export const WORKSPACE_MEMBERS = (workspaceSlug: string) => `WORKSPACE_MEMBERS_${workspaceSlug.toUpperCase()}`;
export const WORKSPACE_INVITATIONS = (workspaceSlug: string) => `WORKSPACE_INVITATIONS_${workspaceSlug.toString()}`;
export const WORKSPACE_INVITATION = (invitationId: string) => `WORKSPACE_INVITATION_${invitationId}`;
export const PROJECT_DETAILS = (projectId: string) => `PROJECT_DETAILS_${projectId.toUpperCase()}`;
export const PROJECT_MEMBERS = (projectId: string) => `PROJECT_MEMBERS_${projectId.toUpperCase()}`;
export const PROJECT_ISSUES_LIST = (workspaceSlug: string, projectId: string) =>

View File

@ -1,95 +0,0 @@
import useSWR from "swr";
// fetch keys
import { COMMENT_REACTION_LIST } from "@/constants/fetch-keys";
// services
import { groupReactions } from "@/helpers/emoji.helper";
import { IssueReactionService } from "@/services/issue";
// helpers
import { useUser } from "./store";
// hooks
// services
const issueReactionService = new IssueReactionService();
const useCommentReaction = (
workspaceSlug?: string | string[] | null,
projectId?: string | string[] | null,
commendId?: string | string[] | null
) => {
const {
data: commentReactions,
mutate: mutateCommentReactions,
error,
} = useSWR(
workspaceSlug && projectId && commendId
? COMMENT_REACTION_LIST(workspaceSlug.toString(), projectId.toString(), commendId.toString())
: null,
workspaceSlug && projectId && commendId
? () =>
issueReactionService.listIssueCommentReactions(
workspaceSlug.toString(),
projectId.toString(),
commendId.toString()
)
: null
);
const user = useUser();
const groupedReactions = groupReactions(commentReactions || [], "reaction");
/**
* @description Use this function to create user's reaction to an issue. This function will mutate the reactions state.
* @param {string} reaction
* @example handleReactionDelete("123") // 123 -> is emoji hexa-code
*/
const handleReactionCreate = async (reaction: string) => {
if (!workspaceSlug || !projectId || !commendId) return;
const data = await issueReactionService.createIssueCommentReaction(
workspaceSlug.toString(),
projectId.toString(),
commendId.toString(),
{ reaction }
);
mutateCommentReactions((prev: any) => [...(prev || []), data]);
};
/**
* @description Use this function to delete user's reaction from an issue. This function will mutate the reactions state.
* @param {string} reaction
* @example handleReactionDelete("123") // 123 -> is emoji hexa-code
*/
const handleReactionDelete = async (reaction: string) => {
if (!workspaceSlug || !projectId || !commendId) return;
mutateCommentReactions(
(prevData: any) =>
prevData?.filter((r: any) => r.actor !== user?.currentUser?.id || r.reaction !== reaction) || [],
false
);
await issueReactionService.deleteIssueCommentReaction(
workspaceSlug.toString(),
projectId.toString(),
commendId.toString(),
reaction
);
mutateCommentReactions();
};
return {
isLoading: !commentReactions && !error,
commentReactions,
groupedReactions,
handleReactionCreate,
handleReactionDelete,
mutateCommentReactions,
} as const;
};
export default useCommentReaction;

View File

@ -1,31 +0,0 @@
import { useEffect, useRef } from "react";
import { DraggableProvided, DraggableStateSnapshot } from "@hello-pangea/dnd";
import { createPortal } from "react-dom";
const useDraggableInPortal = () => {
const self = useRef<Element>();
useEffect(() => {
const div = document.createElement("div");
div.style.position = "absolute";
div.style.pointerEvents = "none";
div.style.top = "0";
div.style.width = "100%";
div.style.height = "100%";
self.current = div;
document.body.appendChild(div);
return () => {
document.body.removeChild(div);
};
}, [self.current]);
return (render: any) => (provided: DraggableProvided, snapshot: DraggableStateSnapshot) => {
const element = render(provided, snapshot);
if (self.current && snapshot?.isDragging) {
return createPortal(element, self.current);
}
return element;
};
};
export default useDraggableInPortal;

View File

@ -1,53 +0,0 @@
import { useEffect } from "react";
import { useRouter } from "next/router";
import useSWR from "swr";
// services
import { CURRENT_USER } from "@/constants/fetch-keys";
import { UserService } from "@/services/user.service";
// constants
// types
import type { IUser } from "@plane/types";
// services
const userService = new UserService();
export default function useUser({ redirectTo = "", redirectIfFound = false, options = {} } = {}) {
const router = useRouter();
// API to fetch user information
const { data, isLoading, error, mutate } = useSWR<IUser>(CURRENT_USER, () => userService.currentUser(), options);
const user = error ? undefined : data;
useEffect(() => {
// if no redirect needed, just return (example: already on /dashboard)
// if user data not yet there (fetch in progress, logged in or not) then don't do anything yet
if (!redirectTo || !user) return;
if (
// If redirectTo is set, redirect if the user was not found.
(redirectTo && !redirectIfFound) ||
// If redirectIfFound is also set, redirect if the user was found
(redirectIfFound && user)
) {
router.push(redirectTo);
return;
// const nextLocation = router.asPath.split("?next_path=")[1];
// if (nextLocation) {
// router.push(nextLocation as string);
// return;
// } else {
// router.push("/");
// return;
// }
}
}, [user, redirectIfFound, redirectTo, router]);
return {
user,
isUserLoading: isLoading,
mutateUser: mutate,
userError: error,
// assignedIssuesLength: user?.assigned_issues ?? 0,
// workspaceInvitesLength: user?.workspace_invites ?? 0,
};
}