From cda5f3cff7fd553b94a035006574d0233a6f107e Mon Sep 17 00:00:00 2001 From: dakshmehta007 Date: Wed, 11 Sep 2024 17:53:48 +0530 Subject: [PATCH 1/2] Normalize all the line endings --- backend/src/handlers/errorHandlers.js | 154 +++++++++--------- backend/src/models/coreModels/Upload.js | 146 ++++++++--------- frontend/.gitignore | 48 +++--- frontend/src/RootApp.jsx | 19 ++- .../src/components/Theme/ThemeContext.jsx | 25 +++ frontend/src/components/Theme/ThemeToggle.jsx | 15 ++ frontend/src/style/app.css | 24 +++ 7 files changed, 250 insertions(+), 181 deletions(-) create mode 100644 frontend/src/components/Theme/ThemeContext.jsx create mode 100644 frontend/src/components/Theme/ThemeToggle.jsx diff --git a/backend/src/handlers/errorHandlers.js b/backend/src/handlers/errorHandlers.js index e433f3f16..77b228f93 100644 --- a/backend/src/handlers/errorHandlers.js +++ b/backend/src/handlers/errorHandlers.js @@ -1,77 +1,77 @@ -/* - Catch Errors Handler - - With async/await, you need some way to catch errors - Instead of using try{} catch(e) {} in each controller, we wrap the function in - catchErrors(), catch any errors they throw, and pass it along to our express middleware with next() -*/ - -exports.catchErrors = (fn) => { - return function (req, res, next) { - return fn(req, res, next).catch((error) => { - if (error.name == 'ValidationError') { - return res.status(400).json({ - success: false, - result: null, - message: 'Required fields are not supplied', - controller: fn.name, - error: error, - }); - } else { - // Server Error - return res.status(500).json({ - success: false, - result: null, - message: error.message, - controller: fn.name, - error: error, - }); - } - }); - }; -}; - -/* - Not Found Error Handler - - If we hit a route that is not found, we mark it as 404 and pass it along to the next error handler to display -*/ -exports.notFound = (req, res, next) => { - return res.status(404).json({ - success: false, - message: "Api url doesn't exist ", - }); -}; - -/* - Development Error Handler - - In development we show good error messages so if we hit a syntax error or any other previously un-handled error, we can show good info on what happened -*/ -exports.developmentErrors = (error, req, res, next) => { - error.stack = error.stack || ''; - const errorDetails = { - message: error.message, - status: error.status, - stackHighlighted: error.stack.replace(/[a-z_-\d]+.js:\d+:\d+/gi, '$&'), - }; - - return res.status(500).json({ - success: false, - message: error.message, - error: error, - }); -}; - -/* - Production Error Handler - - No stacktraces are leaked to admin -*/ -exports.productionErrors = (error, req, res, next) => { - return res.status(500).json({ - success: false, - message: error.message, - error: error, - }); -}; +/* + Catch Errors Handler + + With async/await, you need some way to catch errors + Instead of using try{} catch(e) {} in each controller, we wrap the function in + catchErrors(), catch any errors they throw, and pass it along to our express middleware with next() +*/ + +exports.catchErrors = (fn) => { + return function (req, res, next) { + return fn(req, res, next).catch((error) => { + if (error.name == 'ValidationError') { + return res.status(400).json({ + success: false, + result: null, + message: 'Required fields are not supplied', + controller: fn.name, + error: error, + }); + } else { + // Server Error + return res.status(500).json({ + success: false, + result: null, + message: error.message, + controller: fn.name, + error: error, + }); + } + }); + }; +}; + +/* + Not Found Error Handler + + If we hit a route that is not found, we mark it as 404 and pass it along to the next error handler to display +*/ +exports.notFound = (req, res, next) => { + return res.status(404).json({ + success: false, + message: "Api url doesn't exist ", + }); +}; + +/* + Development Error Handler + + In development we show good error messages so if we hit a syntax error or any other previously un-handled error, we can show good info on what happened +*/ +exports.developmentErrors = (error, req, res, next) => { + error.stack = error.stack || ''; + const errorDetails = { + message: error.message, + status: error.status, + stackHighlighted: error.stack.replace(/[a-z_-\d]+.js:\d+:\d+/gi, '$&'), + }; + + return res.status(500).json({ + success: false, + message: error.message, + error: error, + }); +}; + +/* + Production Error Handler + + No stacktraces are leaked to admin +*/ +exports.productionErrors = (error, req, res, next) => { + return res.status(500).json({ + success: false, + message: error.message, + error: error, + }); +}; diff --git a/backend/src/models/coreModels/Upload.js b/backend/src/models/coreModels/Upload.js index 78c31c1a7..cfb143a6e 100644 --- a/backend/src/models/coreModels/Upload.js +++ b/backend/src/models/coreModels/Upload.js @@ -1,73 +1,73 @@ -const mongoose = require('mongoose'); - -const uploadSchema = new mongoose.Schema({ - removed: { - type: Boolean, - default: false, - }, - enabled: { - type: Boolean, - default: true, - }, - - modelName: { - type: String, - trim: true, - }, - fieldId: { - type: String, - required: true, - }, - fileName: { - type: String, - required: true, - }, - fileType: { - type: String, - enum: [ - 'jpeg', - 'jpg', - 'png', - 'gif', - 'webp', - 'doc', - 'txt', - 'csv', - 'docx', - 'xls', - 'xlsx', - 'pdf', - 'zip', - 'rar', - 'mp4', - 'mov', - 'avi', - 'mp3', - 'm4a', - 'webm', - ], - required: true, - }, - isPublic: { - type: Boolean, - required: true, - }, - userID: { - type: mongoose.SchemaTypes.ObjectId, - required: true, - }, - isSecure: { - type: Boolean, - required: true, - }, - path: { - type: String, - required: true, - }, - created: { - type: Date, - default: Date.now, - }, -}); - -module.exports = mongoose.model('Upload ', uploadSchema); +const mongoose = require('mongoose'); + +const uploadSchema = new mongoose.Schema({ + removed: { + type: Boolean, + default: false, + }, + enabled: { + type: Boolean, + default: true, + }, + + modelName: { + type: String, + trim: true, + }, + fieldId: { + type: String, + required: true, + }, + fileName: { + type: String, + required: true, + }, + fileType: { + type: String, + enum: [ + 'jpeg', + 'jpg', + 'png', + 'gif', + 'webp', + 'doc', + 'txt', + 'csv', + 'docx', + 'xls', + 'xlsx', + 'pdf', + 'zip', + 'rar', + 'mp4', + 'mov', + 'avi', + 'mp3', + 'm4a', + 'webm', + ], + required: true, + }, + isPublic: { + type: Boolean, + required: true, + }, + userID: { + type: mongoose.SchemaTypes.ObjectId, + required: true, + }, + isSecure: { + type: Boolean, + required: true, + }, + path: { + type: String, + required: true, + }, + created: { + type: Date, + default: Date.now, + }, +}); + +module.exports = mongoose.model('Upload ', uploadSchema); diff --git a/frontend/.gitignore b/frontend/.gitignore index 65c2dffbc..30189e79e 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -1,24 +1,24 @@ -# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. - -# dependencies -/node_modules -/.pnp -.pnp.js - -# testing -/coverage - -# production -/dist - -# misc -.DS_Store -.env.local -.env.development.local -.env.test.local -.env.production.local - -npm-debug.log* -yarn-debug.log* -yarn-error.log* - +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/dist + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* + diff --git a/frontend/src/RootApp.jsx b/frontend/src/RootApp.jsx index 3126a3a99..8542b6e2e 100644 --- a/frontend/src/RootApp.jsx +++ b/frontend/src/RootApp.jsx @@ -5,17 +5,22 @@ import { BrowserRouter } from 'react-router-dom'; import { Provider } from 'react-redux'; import store from '@/redux/store'; import PageLoader from '@/components/PageLoader'; +import { ThemeProvider } from './components/Theme/ThemeContext' +import ThemeToggle from 'components/Theme/ThemeToggle' const IdurarOs = lazy(() => import('./apps/IdurarOs')); export default function RoutApp() { return ( - - - }> - - - - + + + + }> + + + + + + ); } diff --git a/frontend/src/components/Theme/ThemeContext.jsx b/frontend/src/components/Theme/ThemeContext.jsx new file mode 100644 index 000000000..5e3ce7a42 --- /dev/null +++ b/frontend/src/components/Theme/ThemeContext.jsx @@ -0,0 +1,25 @@ +// src/ThemeContext.js +import React, { createContext, useState, useEffect } from 'react'; + +const ThemeContext = createContext(); + +export const ThemeProvider = ({ children }) => { + const [theme, setTheme] = useState(localStorage.getItem('theme') || 'light'); + + useEffect(() => { + localStorage.setItem('theme', theme); + document.body.className = theme; + }, [theme]); + + const toggleTheme = () => { + setTheme((prevTheme) => (prevTheme === 'light' ? 'dark' : 'light')); + }; + + return ( + + {children} + + ); +}; + +export default ThemeContext; diff --git a/frontend/src/components/Theme/ThemeToggle.jsx b/frontend/src/components/Theme/ThemeToggle.jsx new file mode 100644 index 000000000..b8f8ccb8d --- /dev/null +++ b/frontend/src/components/Theme/ThemeToggle.jsx @@ -0,0 +1,15 @@ +// src/ThemeToggle.js +import React, { useContext } from 'react'; +import ThemeContext from './ThemeContext'; + +const ThemeToggle = () => { + const { theme, toggleTheme } = useContext(ThemeContext); + + return ( + + ); +}; + +export default ThemeToggle; diff --git a/frontend/src/style/app.css b/frontend/src/style/app.css index 9e75176dd..63c25df04 100644 --- a/frontend/src/style/app.css +++ b/frontend/src/style/app.css @@ -9,3 +9,27 @@ @import './partials/sidePanel.css'; @import './partials/collapseBox.css'; @import './partials/erp.css'; + +/* src/App.css */ +body.light { + --background-color: white; + --text-color: black; + } + + body.dark { + --background-color: black; + --text-color: white; + } + + body { + background-color: var(--background-color); + color: var(--text-color); + transition: background-color 0.3s, color 0.3s; + } + + button { + margin: 20px; + padding: 10px 20px; + cursor: pointer; + } + \ No newline at end of file From a1eab54dfce6a8354c1a17832b5a6c242789cc08 Mon Sep 17 00:00:00 2001 From: dakshmehta007 Date: Wed, 11 Sep 2024 17:58:22 +0530 Subject: [PATCH 2/2] Added the Dark-Light Mode functionality --- frontend/src/components/Theme/ThemeContext.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/Theme/ThemeContext.jsx b/frontend/src/components/Theme/ThemeContext.jsx index 5e3ce7a42..02c307306 100644 --- a/frontend/src/components/Theme/ThemeContext.jsx +++ b/frontend/src/components/Theme/ThemeContext.jsx @@ -22,4 +22,4 @@ export const ThemeProvider = ({ children }) => { ); }; -export default ThemeContext; +export default ThemeContext; \ No newline at end of file