This commit is contained in:
giancarlo
2024-03-24 02:23:22 +08:00
parent 648d77b430
commit bce3479368
589 changed files with 37067 additions and 9596 deletions

View File

@@ -0,0 +1,46 @@
{
"name": "@kit/shared",
"private": true,
"version": "0.1.0",
"scripts": {
"clean": "git clean -xdf .turbo node_modules",
"format": "prettier --check \"**/*.{ts,tsx}\"",
"lint": "eslint .",
"typecheck": "tsc --noEmit"
},
"prettier": "@kit/prettier-config",
"exports": {
"./mailer": "./src/mailer.ts",
"./logger": "./src/logger.ts",
"./hooks/*": "./src/hooks/*.ts",
"./contexts/*": "./src/contexts/*.ts",
"./cookies/*": "./src/cookies/*.ts",
"./utils": "./src/utils.ts"
},
"peerDependencies": {
"react": "^18.2.0"
},
"dependencies": {
"pino": "^8.19.0"
},
"devDependencies": {
"@kit/prettier-config": "0.1.0",
"@kit/eslint-config": "0.2.0",
"@kit/tailwind-config": "0.1.0",
"@kit/tsconfig": "0.1.0"
},
"eslintConfig": {
"root": true,
"extends": [
"@kit/eslint-config/base",
"@kit/eslint-config/react"
]
},
"typesVersions": {
"*": {
"*": [
"src/*"
]
}
}
}

View File

@@ -0,0 +1,5 @@
'use client';
import { createContext } from 'react';
export const CsrfTokenContext = createContext<string | null>(null);

View 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;
}

View 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;
}

View 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;

View 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;

View 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 };

View File

@@ -0,0 +1,3 @@
export function isBrowser() {
return typeof window !== 'undefined';
}

View File

@@ -0,0 +1,8 @@
{
"extends": "@kit/tsconfig/base.json",
"compilerOptions": {
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
},
"include": ["*.ts", "src"],
"exclude": ["node_modules"]
}