Cleanup
This commit is contained in:
5
packages/shared/src/contexts/csrf.context.ts
Normal file
5
packages/shared/src/contexts/csrf.context.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
'use client';
|
||||
|
||||
import { createContext } from 'react';
|
||||
|
||||
export const CsrfTokenContext = createContext<string | null>(null);
|
||||
7
packages/shared/src/cookies/sidebar-state.cookie.ts
Normal file
7
packages/shared/src/cookies/sidebar-state.cookie.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
const SIDEBAR_STATE_COOKIE_NAME = 'sidebarState';
|
||||
|
||||
export function parseSidebarStateCookie() {
|
||||
return cookies().get(SIDEBAR_STATE_COOKIE_NAME)?.value;
|
||||
}
|
||||
7
packages/shared/src/cookies/theme.cookie.ts
Normal file
7
packages/shared/src/cookies/theme.cookie.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
const THEME_COOKIE_NAME = 'theme';
|
||||
|
||||
export function parseThemeCookie() {
|
||||
return cookies().get(THEME_COOKIE_NAME)?.value;
|
||||
}
|
||||
15
packages/shared/src/hooks/use-csrf-token.ts
Normal file
15
packages/shared/src/hooks/use-csrf-token.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { useContext } from 'react';
|
||||
|
||||
import { CsrfTokenContext } from '@kit/contexts/csrf.context';
|
||||
|
||||
/**
|
||||
* @description Retrieves the current CSRF token in the CsrfTokenContext context
|
||||
* If not found, it will return an empty string. If required, the API will throw an error
|
||||
*/
|
||||
function useCsrfToken() {
|
||||
const token = useContext(CsrfTokenContext);
|
||||
|
||||
return token ?? '';
|
||||
}
|
||||
|
||||
export default useCsrfToken;
|
||||
19
packages/shared/src/hooks/use-refresh-route.ts
Normal file
19
packages/shared/src/hooks/use-refresh-route.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
/**
|
||||
* @name useRefreshRoute
|
||||
* @description Refresh the current page. Useful for when you need to
|
||||
* refresh the data on a page after a mutation. This is a temporary
|
||||
* workaround until Next.js adds mutations
|
||||
*/
|
||||
function useRefreshRoute() {
|
||||
const router = useRouter();
|
||||
|
||||
return useCallback(() => {
|
||||
router.refresh();
|
||||
}, [router]);
|
||||
}
|
||||
|
||||
export default useRefreshRoute;
|
||||
13
packages/shared/src/logger.ts
Normal file
13
packages/shared/src/logger.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { pino } from 'pino';
|
||||
|
||||
const Logger = pino({
|
||||
browser: {
|
||||
asObject: true,
|
||||
},
|
||||
level: 'debug',
|
||||
base: {
|
||||
env: process.env.NODE_ENV,
|
||||
},
|
||||
});
|
||||
|
||||
export { Logger };
|
||||
3
packages/shared/src/utils.ts
Normal file
3
packages/shared/src/utils.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export function isBrowser() {
|
||||
return typeof window !== 'undefined';
|
||||
}
|
||||
Reference in New Issue
Block a user