feat: init
This commit is contained in:
2
apps/space/core/hooks/store/publish/index.ts
Normal file
2
apps/space/core/hooks/store/publish/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./use-publish-list";
|
||||
export * from "./use-publish";
|
||||
11
apps/space/core/hooks/store/publish/use-publish-list.ts
Normal file
11
apps/space/core/hooks/store/publish/use-publish-list.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { useContext } from "react";
|
||||
// lib
|
||||
import { StoreContext } from "@/lib/store-provider";
|
||||
// store
|
||||
import type { IPublishListStore } from "@/store/publish/publish_list.store";
|
||||
|
||||
export const usePublishList = (): IPublishListStore => {
|
||||
const context = useContext(StoreContext);
|
||||
if (context === undefined) throw new Error("usePublishList must be used within StoreProvider");
|
||||
return context.publishList;
|
||||
};
|
||||
11
apps/space/core/hooks/store/publish/use-publish.ts
Normal file
11
apps/space/core/hooks/store/publish/use-publish.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { useContext } from "react";
|
||||
// lib
|
||||
import { StoreContext } from "@/lib/store-provider";
|
||||
// store
|
||||
import type { PublishStore } from "@/store/publish/publish.store";
|
||||
|
||||
export const usePublish = (anchor: string): PublishStore => {
|
||||
const context = useContext(StoreContext);
|
||||
if (context === undefined) throw new Error("usePublish must be used within StoreProvider");
|
||||
return context.publishList.publishMap?.[anchor] ?? {};
|
||||
};
|
||||
11
apps/space/core/hooks/store/use-cycle.ts
Normal file
11
apps/space/core/hooks/store/use-cycle.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { useContext } from "react";
|
||||
// lib
|
||||
import { StoreContext } from "@/lib/store-provider";
|
||||
// store
|
||||
import type { ICycleStore } from "@/store/cycle.store";
|
||||
|
||||
export const useCycle = (): ICycleStore => {
|
||||
const context = useContext(StoreContext);
|
||||
if (context === undefined) throw new Error("useCycle must be used within StoreProvider");
|
||||
return context.cycle;
|
||||
};
|
||||
11
apps/space/core/hooks/store/use-instance.ts
Normal file
11
apps/space/core/hooks/store/use-instance.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { useContext } from "react";
|
||||
// lib
|
||||
import { StoreContext } from "@/lib/store-provider";
|
||||
// store
|
||||
import type { IInstanceStore } from "@/store/instance.store";
|
||||
|
||||
export const useInstance = (): IInstanceStore => {
|
||||
const context = useContext(StoreContext);
|
||||
if (context === undefined) throw new Error("useUserProfile must be used within StoreProvider");
|
||||
return context.instance;
|
||||
};
|
||||
11
apps/space/core/hooks/store/use-issue-details.tsx
Normal file
11
apps/space/core/hooks/store/use-issue-details.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
import { useContext } from "react";
|
||||
// lib
|
||||
import { StoreContext } from "@/lib/store-provider";
|
||||
// store
|
||||
import type { IIssueDetailStore } from "@/store/issue-detail.store";
|
||||
|
||||
export const useIssueDetails = (): IIssueDetailStore => {
|
||||
const context = useContext(StoreContext);
|
||||
if (context === undefined) throw new Error("useUserProfile must be used within StoreProvider");
|
||||
return context.issueDetail;
|
||||
};
|
||||
11
apps/space/core/hooks/store/use-issue-filter.ts
Normal file
11
apps/space/core/hooks/store/use-issue-filter.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { useContext } from "react";
|
||||
// lib
|
||||
import { StoreContext } from "@/lib/store-provider";
|
||||
// store
|
||||
import type { IIssueFilterStore } from "@/store/issue-filters.store";
|
||||
|
||||
export const useIssueFilter = (): IIssueFilterStore => {
|
||||
const context = useContext(StoreContext);
|
||||
if (context === undefined) throw new Error("useUserProfile must be used within StoreProvider");
|
||||
return context.issueFilter;
|
||||
};
|
||||
11
apps/space/core/hooks/store/use-issue.ts
Normal file
11
apps/space/core/hooks/store/use-issue.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { useContext } from "react";
|
||||
// lib
|
||||
import { StoreContext } from "@/lib/store-provider";
|
||||
// store
|
||||
import type { IIssueStore } from "@/store/issue.store";
|
||||
|
||||
export const useIssue = (): IIssueStore => {
|
||||
const context = useContext(StoreContext);
|
||||
if (context === undefined) throw new Error("useIssue must be used within StoreProvider");
|
||||
return context.issue;
|
||||
};
|
||||
11
apps/space/core/hooks/store/use-label.ts
Normal file
11
apps/space/core/hooks/store/use-label.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { useContext } from "react";
|
||||
// lib
|
||||
import { StoreContext } from "@/lib/store-provider";
|
||||
// store
|
||||
import type { IIssueLabelStore } from "@/store/label.store";
|
||||
|
||||
export const useLabel = (): IIssueLabelStore => {
|
||||
const context = useContext(StoreContext);
|
||||
if (context === undefined) throw new Error("useLabel must be used within StoreProvider");
|
||||
return context.label;
|
||||
};
|
||||
11
apps/space/core/hooks/store/use-member.ts
Normal file
11
apps/space/core/hooks/store/use-member.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { useContext } from "react";
|
||||
// lib
|
||||
import { StoreContext } from "@/lib/store-provider";
|
||||
// store
|
||||
import type { IIssueMemberStore } from "@/store/members.store";
|
||||
|
||||
export const useMember = (): IIssueMemberStore => {
|
||||
const context = useContext(StoreContext);
|
||||
if (context === undefined) throw new Error("useMember must be used within StoreProvider");
|
||||
return context.member;
|
||||
};
|
||||
11
apps/space/core/hooks/store/use-module.ts
Normal file
11
apps/space/core/hooks/store/use-module.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { useContext } from "react";
|
||||
// lib
|
||||
import { StoreContext } from "@/lib/store-provider";
|
||||
// store
|
||||
import type { IIssueModuleStore } from "@/store/module.store";
|
||||
|
||||
export const useModule = (): IIssueModuleStore => {
|
||||
const context = useContext(StoreContext);
|
||||
if (context === undefined) throw new Error("useModule must be used within StoreProvider");
|
||||
return context.module;
|
||||
};
|
||||
11
apps/space/core/hooks/store/use-state.ts
Normal file
11
apps/space/core/hooks/store/use-state.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { useContext } from "react";
|
||||
// lib
|
||||
import { StoreContext } from "@/lib/store-provider";
|
||||
// store
|
||||
import type { IStateStore } from "@/store/state.store";
|
||||
|
||||
export const useStates = (): IStateStore => {
|
||||
const context = useContext(StoreContext);
|
||||
if (context === undefined) throw new Error("useState must be used within StoreProvider");
|
||||
return context.state;
|
||||
};
|
||||
11
apps/space/core/hooks/store/use-user-profile.ts
Normal file
11
apps/space/core/hooks/store/use-user-profile.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { useContext } from "react";
|
||||
// lib
|
||||
import { StoreContext } from "@/lib/store-provider";
|
||||
// store
|
||||
import type { IProfileStore } from "@/store/profile.store";
|
||||
|
||||
export const useUserProfile = (): IProfileStore => {
|
||||
const context = useContext(StoreContext);
|
||||
if (context === undefined) throw new Error("useUserProfile must be used within StoreProvider");
|
||||
return context.user.profile;
|
||||
};
|
||||
11
apps/space/core/hooks/store/use-user.ts
Normal file
11
apps/space/core/hooks/store/use-user.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { useContext } from "react";
|
||||
// lib
|
||||
import { StoreContext } from "@/lib/store-provider";
|
||||
// store
|
||||
import type { IUserStore } from "@/store/user.store";
|
||||
|
||||
export const useUser = (): IUserStore => {
|
||||
const context = useContext(StoreContext);
|
||||
if (context === undefined) throw new Error("useUser must be used within StoreProvider");
|
||||
return context.user;
|
||||
};
|
||||
29
apps/space/core/hooks/use-clipboard-write-permission.tsx
Normal file
29
apps/space/core/hooks/use-clipboard-write-permission.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
const useClipboardWritePermission = () => {
|
||||
const [isClipboardWriteAllowed, setClipboardWriteAllowed] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const checkClipboardWriteAccess = () => {
|
||||
navigator.permissions
|
||||
//eslint-disable-next-line no-undef
|
||||
.query({ name: "clipboard-write" as PermissionName })
|
||||
.then((result) => {
|
||||
if (result.state === "granted") {
|
||||
setClipboardWriteAllowed(true);
|
||||
} else {
|
||||
setClipboardWriteAllowed(false);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
setClipboardWriteAllowed(false);
|
||||
});
|
||||
};
|
||||
|
||||
checkClipboardWriteAccess();
|
||||
}, []);
|
||||
|
||||
return isClipboardWriteAllowed;
|
||||
};
|
||||
|
||||
export default useClipboardWritePermission;
|
||||
44
apps/space/core/hooks/use-intersection-observer.tsx
Normal file
44
apps/space/core/hooks/use-intersection-observer.tsx
Normal file
@@ -0,0 +1,44 @@
|
||||
import type { RefObject } from "react";
|
||||
import { useEffect } from "react";
|
||||
|
||||
export type UseIntersectionObserverProps = {
|
||||
containerRef: RefObject<HTMLDivElement | null> | undefined;
|
||||
elementRef: HTMLElement | null;
|
||||
callback: () => void;
|
||||
rootMargin?: string;
|
||||
};
|
||||
|
||||
export const useIntersectionObserver = (
|
||||
containerRef: RefObject<HTMLDivElement | null>,
|
||||
elementRef: HTMLElement | null,
|
||||
callback: (() => void) | undefined,
|
||||
rootMargin?: string
|
||||
) => {
|
||||
useEffect(() => {
|
||||
if (elementRef) {
|
||||
const observer = new IntersectionObserver(
|
||||
(entries) => {
|
||||
if (entries[entries.length - 1].isIntersecting) {
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
root: containerRef?.current,
|
||||
rootMargin,
|
||||
}
|
||||
);
|
||||
observer.observe(elementRef);
|
||||
return () => {
|
||||
if (elementRef) {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
observer.unobserve(elementRef);
|
||||
}
|
||||
};
|
||||
}
|
||||
// When i am passing callback as a dependency, it is causing infinite loop,
|
||||
// Please make sure you fix this eslint lint disable error with caution
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [rootMargin, callback, elementRef, containerRef.current]);
|
||||
};
|
||||
17
apps/space/core/hooks/use-is-in-iframe.tsx
Normal file
17
apps/space/core/hooks/use-is-in-iframe.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
const useIsInIframe = () => {
|
||||
const [isInIframe, setIsInIframe] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const checkIfInIframe = () => {
|
||||
setIsInIframe(window.self !== window.top);
|
||||
};
|
||||
|
||||
checkIfInIframe();
|
||||
}, []);
|
||||
|
||||
return isInIframe;
|
||||
};
|
||||
|
||||
export default useIsInIframe;
|
||||
43
apps/space/core/hooks/use-mention.tsx
Normal file
43
apps/space/core/hooks/use-mention.tsx
Normal file
@@ -0,0 +1,43 @@
|
||||
import { useRef, useEffect } from "react";
|
||||
import useSWR from "swr";
|
||||
// plane imports
|
||||
import { UserService } from "@plane/services";
|
||||
import type { IUser } from "@plane/types";
|
||||
|
||||
export const useMention = () => {
|
||||
const userService = new UserService();
|
||||
const { data: user, isLoading: userDataLoading } = useSWR("currentUser", async () => userService.me());
|
||||
|
||||
const userRef = useRef<IUser | undefined>();
|
||||
|
||||
useEffect(() => {
|
||||
if (userRef) {
|
||||
userRef.current = user;
|
||||
}
|
||||
}, [user]);
|
||||
|
||||
const waitForUserDate = async () =>
|
||||
new Promise<IUser>((resolve) => {
|
||||
const checkData = () => {
|
||||
if (userRef.current) {
|
||||
resolve(userRef.current);
|
||||
} else {
|
||||
setTimeout(checkData, 100);
|
||||
}
|
||||
};
|
||||
checkData();
|
||||
});
|
||||
|
||||
const mentionHighlights = async () => {
|
||||
if (!userDataLoading && userRef.current) {
|
||||
return [userRef.current.id];
|
||||
} else {
|
||||
const user = await waitForUserDate();
|
||||
return [user.id];
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
mentionHighlights,
|
||||
};
|
||||
};
|
||||
19
apps/space/core/hooks/use-timer.tsx
Normal file
19
apps/space/core/hooks/use-timer.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
const TIMER = 30;
|
||||
|
||||
const useTimer = (initialValue: number = TIMER) => {
|
||||
const [timer, setTimer] = useState(initialValue);
|
||||
|
||||
useEffect(() => {
|
||||
const interval = setInterval(() => {
|
||||
setTimer((prev) => prev - 1);
|
||||
}, 1000);
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
|
||||
return { timer, setTimer };
|
||||
};
|
||||
|
||||
export default useTimer;
|
||||
Reference in New Issue
Block a user