📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
typescriptify hooks and hoc
Blue Mousef3698b868e02
diff --git a/src/hoc/protected.js b/src/hoc/protected.tsxsimilarity index 54%rename from src/hoc/protected.jsrename to src/hoc/protected.tsxindex 195f63bf3..0560ffd40 100644--- a/src/hoc/protected.js+++ b/src/hoc/protected.tsx@@ -1,20 +1,27 @@import { useSelector } from 'react-redux'import { Redirect } from 'react-router-dom'++import { StateType } from 'redux/store'import routes from 'routes'+type AuthParamType = {+ selector: (state: StateType) => boolean,+ redirectPath: string+}+export const auth = {authenticated: {- selector: state => state.auth.authenticated,+ selector: (state: StateType) => state.auth.authenticated,redirectPath: routes.signin,},notAuthenticated: {- selector: state => !state.auth.authenticated,+ selector: (state: StateType) => !state.auth.authenticated,redirectPath: routes.dashboard,},}-export const withAuthentication = (WrappedComponent, authParam) => {- const WithAuthentication = (params) => {+export const withAuthentication = (WrappedComponent: any, authParam: AuthParamType) => {+ const WithAuthentication = (params: any) => {const selector = useSelector(authParam.selector)if (!selector) {diff --git a/src/hooks/useOnClickOutside.js b/src/hooks/useOnClickOutside.tssimilarity index 60%rename from src/hooks/useOnClickOutside.jsrename to src/hooks/useOnClickOutside.tsindex e825cfceb..021d2819d 100644--- a/src/hooks/useOnClickOutside.js+++ b/src/hooks/useOnClickOutside.ts@@ -1,9 +1,9 @@-import { useEffect } from 'react'+import React, { useEffect } from 'react'-const useOnClickOutside = (ref, handler) => {+const useOnClickOutside = (ref: React.RefObject<HTMLDivElement>, handler: Function) => {useEffect(() => {- const func = (event) => {- if (!ref.current || ref.current.contains(event.target)) {+ const func = (event: MouseEvent | TouchEvent) => {+ if (!ref.current || ref.current.contains(event.target as Node)) {return}handler(event)diff --git a/src/hooks/usePagination.jsx b/src/hooks/usePagination.tsxsimilarity index 91%rename from src/hooks/usePagination.jsxrename to src/hooks/usePagination.tsxindex c1fe96e32..5e32a07a0 100644--- a/src/hooks/usePagination.jsx+++ b/src/hooks/usePagination.tsx@@ -3,17 +3,17 @@ import { ENTRIES_PER_PAGE_DASHBOARD } from 'redux/constants'export const DOTS = '...'-const range = (start, end) => {+const range = (start: number, end: number) => {const length = end - start + 1return Array.from({ length }, (_, idx) => idx + start)}export const usePagination = (- totalCount,- currentPage,- siblingCount = 1,- pageSize = ENTRIES_PER_PAGE_DASHBOARD,-) => {+ totalCount: number,+ currentPage: number,+ siblingCount: number = 1,+ pageSize: number = ENTRIES_PER_PAGE_DASHBOARD,+): any[] => {const paginationRange = useMemo(() => {const totalPageCount = Math.ceil(totalCount / pageSize)diff --git a/src/hooks/useSize.jsx b/src/hooks/useSize.tssimilarity index 99%rename from src/hooks/useSize.jsxrename to src/hooks/useSize.tsindex 312a9a41c..98f201115 100644--- a/src/hooks/useSize.jsx+++ b/src/hooks/useSize.ts@@ -7,6 +7,7 @@ export default () => {width: 0, height: 0,})const ref = useRef(null)+useEffect(() => {const DOMnode = ref.currentif (!DOMnode) {@@ -23,5 +24,6 @@ export default () => {resizeObserver.unobserve(DOMnode)}}, [])+return [ref, size]}