Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding a toggle button for light or dark mode #384

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 62 additions & 2 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,71 @@
<link rel="icon" type="image/svg+xml" href="/logo.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>MediHub</title>
<style>
:root {
--bg-color: #ffffff;
--text-color: #000000;
--button-bg: #f0f0f0;
--button-text: #000000;
}
[data-theme="dark"] {
--bg-color: #1c1c1c;
--text-color: #ffffff;
--button-bg: #444444;
--button-text: #ffffff;
}
body {
background-color: var(--bg-color);
color: var(--text-color);
font-family: Arial, sans-serif;
transition: background-color 0.3s ease, color 0.3s ease;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}

#root {
text-align: center;
}

.theme-toggle {
background-color: var(--button-bg);
color: var(--button-text);
border: none;
padding: 10px 20px;
cursor: pointer;
border-radius: 5px;
margin-top: 20px;
font-size: 16px;
}
</style>
</head>

<body>
<div id="root"></div>
<div id="root">
<h1>Welcome to MediHub</h1>
<p>Choose between Light and Dark Theme</p>
<button id="theme-toggle" class="theme-toggle">Switch to Dark Theme</button>
</div>

<script>
const themeToggleButton = document.getElementById('theme-toggle');
const currentTheme = localStorage.getItem('theme') || 'light';

document.documentElement.setAttribute('data-theme', currentTheme);
themeToggleButton.textContent = currentTheme === 'dark' ? 'Switch to Light Theme' : 'Switch to Dark Theme';

themeToggleButton.addEventListener('click', function () {
const newTheme = document.documentElement.getAttribute('data-theme') === 'dark' ? 'light' : 'dark';
document.documentElement.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
themeToggleButton.textContent = newTheme === 'dark' ? 'Switch to Light Theme' : 'Switch to Dark Theme';
});
</script>

<script type="module" src="/src/main.jsx"></script>
</body>

</html>
</html>
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@
import React from "react";
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json());
mongoose.connect('mongodb://localhost:27017/mediHub', {
useNewUrlParser: true,
useUnifiedTopology: true,
});
const termsSchema = new mongoose.Schema({
content: String,
updatedAt: { type: Date, default: Date.now },
});
const Terms = mongoose.model('Terms', termsSchema);
app.get('/terms', async (req, res) => {
try {
const terms = await Terms.findOne().sort({ updatedAt: -1 });
if (!terms) {
return res.status(404).json({ message: 'Terms and Conditions not found' });
}
res.json(terms);
} catch (error) {
res.status(500).json({ message: 'Server error' });
}
});
app.put('/terms', async (req, res) => {
const { content } = req.body;

function TermsAndConditionsPage() {
return <div>Terms and Conditions</div>;
}
if (!content) {
return res.status(400).json({ message: 'Content is required' });
}

export default TermsAndConditionsPage;
try {
const newTerms = new Terms({ content });
await newTerms.save();
res.json({ message: 'Terms and Conditions updated successfully', terms: newTerms });
} catch (error) {
res.status(500).json({ message: 'Server error' });
}
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});