lint
This commit is contained in:
@@ -10,7 +10,8 @@
|
|||||||
},
|
},
|
||||||
"formatter": {
|
"formatter": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"indentStyle": "tab"
|
"indentStyle": "space",
|
||||||
|
"indentWidth": 2
|
||||||
},
|
},
|
||||||
"linter": {
|
"linter": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { MujianProvider } from './providers/MujianProvider.tsx';
|
|||||||
import { ReactRouterProvider } from './providers/RouterProvider.tsx';
|
import { ReactRouterProvider } from './providers/RouterProvider.tsx';
|
||||||
|
|
||||||
createRoot(document.getElementById('root')!).render(
|
createRoot(document.getElementById('root')!).render(
|
||||||
<MujianProvider>
|
<MujianProvider>
|
||||||
<ReactRouterProvider />
|
<ReactRouterProvider />
|
||||||
</MujianProvider>,
|
</MujianProvider>,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ import './index.css';
|
|||||||
// import { useGlobalStore } from "@/store/global";
|
// import { useGlobalStore } from "@/store/global";
|
||||||
|
|
||||||
function About() {
|
function About() {
|
||||||
// const { count, increment } = useGlobalStore((state) => state);
|
// const { count, increment } = useGlobalStore((state) => state);
|
||||||
|
|
||||||
return <div>about page</div>;
|
return <div>about page</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default About;
|
export default About;
|
||||||
|
|||||||
@@ -4,39 +4,39 @@ import { isEmpty } from 'lodash-es';
|
|||||||
import { EVENT, useMujian } from '@/providers/MujianProvider';
|
import { EVENT, useMujian } from '@/providers/MujianProvider';
|
||||||
|
|
||||||
function Home() {
|
function Home() {
|
||||||
const { count, increment } = useGlobalStore((state) => state);
|
const { count, increment } = useGlobalStore((state) => state);
|
||||||
const mujian = useMujian();
|
const mujian = useMujian();
|
||||||
|
|
||||||
console.log('count', count);
|
console.log('count', count);
|
||||||
|
|
||||||
console.log('isEmpty', isEmpty(count));
|
console.log('isEmpty', isEmpty(count));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div>
|
<div>
|
||||||
<div className="text-3xl font-bold underline">Hello World2</div>
|
<div className="text-3xl font-bold underline">Hello World2</div>
|
||||||
</div>
|
</div>
|
||||||
<h1>Vite + React</h1>
|
<h1>Vite + React</h1>
|
||||||
<button type="button" onClick={increment}>
|
<button type="button" onClick={increment}>
|
||||||
Increment
|
Increment
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<p>Count: {count}</p>
|
<p>Count: {count}</p>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
mujian.emit(EVENT.MUJIAN_AI_CHAT_SEND_MESSAGE, {
|
mujian.emit(EVENT.MUJIAN_AI_CHAT_SEND_MESSAGE, {
|
||||||
message: 'Hello, World!',
|
message: 'Hello, World!',
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Hello
|
Hello
|
||||||
</button>
|
</button>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Home;
|
export default Home;
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
import { MujianSdk } from '@mujian/js-sdk';
|
import { MujianSdk } from '@mujian/js-sdk';
|
||||||
import {
|
import {
|
||||||
createContext,
|
createContext,
|
||||||
type ReactNode,
|
type ReactNode,
|
||||||
useContext,
|
useContext,
|
||||||
useEffect,
|
useEffect,
|
||||||
useState,
|
useState,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
|
|
||||||
export { EVENT } from '@mujian/js-sdk';
|
export { EVENT } from '@mujian/js-sdk';
|
||||||
@@ -14,38 +14,38 @@ export { EVENT } from '@mujian/js-sdk';
|
|||||||
const MujianContext = createContext<MujianSdk | null>(null);
|
const MujianContext = createContext<MujianSdk | null>(null);
|
||||||
|
|
||||||
export interface MujianProviderProps {
|
export interface MujianProviderProps {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
loadingPage?: ReactNode;
|
loadingPage?: ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MujianProvider = ({
|
export const MujianProvider = ({
|
||||||
children,
|
children,
|
||||||
loadingPage,
|
loadingPage,
|
||||||
}: MujianProviderProps) => {
|
}: MujianProviderProps) => {
|
||||||
const [mujian, setMujian] = useState<MujianSdk | null>(null);
|
const [mujian, setMujian] = useState<MujianSdk | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
const mujian = new MujianSdk();
|
const mujian = new MujianSdk();
|
||||||
await mujian.init();
|
await mujian.init();
|
||||||
setMujian(mujian);
|
setMujian(mujian);
|
||||||
})();
|
})();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MujianContext.Provider value={mujian}>
|
<MujianContext.Provider value={mujian}>
|
||||||
{mujian ? children : (loadingPage ?? 'Mujian is loading')}
|
{mujian ? children : (loadingPage ?? 'Mujian is loading')}
|
||||||
</MujianContext.Provider>
|
</MujianContext.Provider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useMujian = () => {
|
export const useMujian = () => {
|
||||||
const mujian = useContext(MujianContext);
|
const mujian = useContext(MujianContext);
|
||||||
if (!mujian) {
|
if (!mujian) {
|
||||||
const message =
|
const message =
|
||||||
'Mujian is not initialized. Please check that useMujian is called inside MujianProvider';
|
'Mujian is not initialized. Please check that useMujian is called inside MujianProvider';
|
||||||
console.error(message);
|
console.error(message);
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
return mujian;
|
return mujian;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,16 +4,16 @@ import About from '@/pages/about';
|
|||||||
import Home from '@/pages/home';
|
import Home from '@/pages/home';
|
||||||
|
|
||||||
const router = createBrowserRouter([
|
const router = createBrowserRouter([
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
element: <Home />,
|
element: <Home />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/about',
|
path: '/about',
|
||||||
element: <About />,
|
element: <About />,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export const ReactRouterProvider = () => {
|
export const ReactRouterProvider = () => {
|
||||||
return <RouterProvider router={router} />;
|
return <RouterProvider router={router} />;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import { create } from 'zustand';
|
import { create } from 'zustand';
|
||||||
|
|
||||||
type GlobalState = {
|
type GlobalState = {
|
||||||
count: number;
|
count: number;
|
||||||
increment: () => void;
|
increment: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useGlobalStore = create<GlobalState>((set) => ({
|
export const useGlobalStore = create<GlobalState>((set) => ({
|
||||||
count: 0,
|
count: 0,
|
||||||
increment: () => {
|
increment: () => {
|
||||||
console.log('increment');
|
console.log('increment');
|
||||||
set((state) => ({ count: state.count + 1 }));
|
set((state) => ({ count: state.count + 1 }));
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
@import "tailwindcss";
|
@import "tailwindcss";
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
|
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
|
|
||||||
color-scheme: light dark;
|
color-scheme: light dark;
|
||||||
|
|
||||||
font-synthesis: none;
|
font-synthesis: none;
|
||||||
text-rendering: optimizeLegibility;
|
text-rendering: optimizeLegibility;
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
-moz-osx-font-smoothing: grayscale;
|
-moz-osx-font-smoothing: grayscale;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user