Skip to content

Commit

Permalink
feat: integrate react-router-dom for improved routing and refactor Ap…
Browse files Browse the repository at this point in the history
…p component structure
  • Loading branch information
felipepimentel committed Sep 24, 2024
1 parent 65366fa commit 56c26b1
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 47 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"postcss": "^8.4.47",
"prettier": "^3.3.3",
"prettier-plugin-tailwindcss": "^0.6.6",
"react-router-dom": "^6.26.2",
"storybook": "^8.3.2",
"zustand": "^5.0.0-rc.2"
}
Expand Down
46 changes: 5 additions & 41 deletions src/renderer/App.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,11 @@
import React, { useEffect, useState } from 'react';
import { eventBus } from '@events/event-bus';
import { loadActivePlugins } from '@plugin-manager/plugin-manager';
import { PluginProvider } from '@plugin-manager/plugin-context';

const App: React.FC = () => {
const [pluginsLoaded, setPluginsLoaded] = useState(false);

useEffect(() => {
const loadPlugins = async () => {
await loadActivePlugins();
setPluginsLoaded(true);
};
loadPlugins();
}, []);

useEffect(() => {
const handlePluginLoaded = ({ pluginName }: { pluginName: string }) => {
console.log(`Plugin loaded: ${pluginName}`);
};

const handlePluginUnloaded = ({ pluginName }: { pluginName: string }) => {
console.log(`Plugin unloaded: ${pluginName}`);
};

eventBus.on('plugin-loaded', handlePluginLoaded);
eventBus.on('plugin-unloaded', handlePluginUnloaded);

return () => {
eventBus.off('plugin-loaded', handlePluginLoaded);
eventBus.off('plugin-unloaded', handlePluginUnloaded);
};
}, []);

if (!pluginsLoaded) {
return <div>Loading plugins...</div>;
}
import React from 'react';
import { EventBus } from '@events/event-bus';

const App = () => {
// Use EventBus here
return (
<div>
<h1>Main Application</h1>
<PluginProvider>
{/* Render loaded plugins here */}
</PluginProvider>
{/* Your app components */}
</div>
);
};
Expand Down
31 changes: 26 additions & 5 deletions src/state/store-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
import React from 'react';
import { GlobalStoreProvider } from '@state/global-store';
import React, { createContext, useContext, useReducer } from 'react';

export const StoreProvider: React.FC = ({ children }) => (
<GlobalStoreProvider>{children}</GlobalStoreProvider>
);
const initialState = {
// Defina o estado inicial aqui
};

const StoreContext = createContext(initialState);

const storeReducer = (state, action) => {
switch (action.type) {
// Defina os casos do reducer aqui
default:
return state;
}
};

export const StoreProvider = ({ children }) => {
const [state, dispatch] = useReducer(storeReducer, initialState);

return (
<StoreContext.Provider value={{ state, dispatch }}>
{children}
</StoreContext.Provider>
);
};

export const useStore = () => useContext(StoreContext);
10 changes: 9 additions & 1 deletion vite.renderer.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { defineConfig } from 'vite';
import path from 'path';

// https://vitejs.dev/config
export default defineConfig({});
export default defineConfig({
resolve: {
alias: {
'@state': path.resolve(__dirname, 'src/state'),
'@events': path.resolve(__dirname, 'src/events'),
},
},
});
20 changes: 20 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,11 @@
dependencies:
playwright "1.47.2"

"@remix-run/[email protected]":
version "1.19.2"
resolved "https://registry.yarnpkg.com/@remix-run/router/-/router-1.19.2.tgz#0c896535473291cb41f152c180bedd5680a3b273"
integrity sha512-baiMx18+IMuD1yyvOGaHM9QrVUPGGG0jC+z+IPHnRJWUAUvaKuWKyE8gjDj2rzv3sz9zOGoRSPgeBVHRhZnBlA==

"@rollup/pluginutils@^5.0.2":
version "5.1.2"
resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-5.1.2.tgz#d3bc9f0fea4fd4086aaac6aa102f3fa587ce8bd9"
Expand Down Expand Up @@ -7363,6 +7368,21 @@ react-is@^18.0.0:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.3.1.tgz#e83557dc12eae63a99e003a46388b1dcbb44db7e"
integrity sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==

react-router-dom@^6.26.2:
version "6.26.2"
resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-6.26.2.tgz#a6e3b0cbd6bfd508e42b9342099d015a0ac59680"
integrity sha512-z7YkaEW0Dy35T3/QKPYB1LjMK2R1fxnHO8kWpUMTBdfVzZrWOiY9a7CtN8HqdWtDUWd5FY6Dl8HFsqVwH4uOtQ==
dependencies:
"@remix-run/router" "1.19.2"
react-router "6.26.2"

[email protected]:
version "6.26.2"
resolved "https://registry.yarnpkg.com/react-router/-/react-router-6.26.2.tgz#2f0a68999168954431cdc29dd36cec3b6fa44a7e"
integrity sha512-tvN1iuT03kHgOFnLPfLJ8V95eijteveqdOSk+srqfePtQvqCExB8eHOYnlilbOcyJyKnYkr1vJvf7YqotAJu1A==
dependencies:
"@remix-run/router" "1.19.2"

"react@^16.8.0 || ^17.0.0 || ^18.0.0":
version "18.3.1"
resolved "https://registry.yarnpkg.com/react/-/react-18.3.1.tgz#49ab892009c53933625bd16b2533fc754cab2891"
Expand Down

0 comments on commit 56c26b1

Please sign in to comment.