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

Google's Free Certifications Fetch API Implemented | To Fetch Google's Free Certifications & Courses #275

Merged
merged 8 commits into from
Oct 28, 2024
Merged
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
12 changes: 12 additions & 0 deletions PROJECT_STRUCTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
├── postcss.config.mjs
├── public/
│ ├── Logo.svg
│ ├── Mentor 1.jpeg
│ ├── Mentor 2.jpeg
│ ├── Mentor 3.png
│ ├── Newsletter.png
│ ├── avatar.png
│ ├── avatar1.png
Expand Down Expand Up @@ -90,11 +93,18 @@
│ │ │ ├── SingleEvent/
│ │ │ │ └── [id]/
│ │ │ │ └── page.jsx
│ │ │ ├── Stories-Achievements/
│ │ │ │ ├── achievements.js
│ │ │ │ ├── mentors.js
│ │ │ │ └── page.jsx
│ │ │ ├── Subscribe/
│ │ │ │ └── page.jsx
│ │ │ ├── TeamsGallery/
│ │ │ │ ├── Teams.js
│ │ │ │ └── page.jsx
│ │ │ ├── TechToolkits/
│ │ │ │ ├── page.jsx
│ │ │ │ └── techStacks.js
│ │ │ ├── TermsAndConditions/
│ │ │ │ └── page.jsx
│ │ │ ├── api/
Expand Down Expand Up @@ -182,6 +192,8 @@
│ │ ├── Hackathon.js
│ │ ├── Projects.js
│ │ ├── cpp-content.js
│ │ ├── dsa-content.js
│ │ ├── dsa-track-content.js
│ │ └── utils.js
│ └── public/
│ └── GDSC-RCIIT Logo.png
Expand Down
12 changes: 12 additions & 0 deletions repo_structure.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
├── postcss.config.mjs
├── public/
│ ├── Logo.svg
│ ├── Mentor 1.jpeg
│ ├── Mentor 2.jpeg
│ ├── Mentor 3.png
│ ├── Newsletter.png
│ ├── avatar.png
│ ├── avatar1.png
Expand Down Expand Up @@ -86,11 +89,18 @@
│ │ │ ├── SingleEvent/
│ │ │ │ └── [id]/
│ │ │ │ └── page.jsx
│ │ │ ├── Stories-Achievements/
│ │ │ │ ├── achievements.js
│ │ │ │ ├── mentors.js
│ │ │ │ └── page.jsx
│ │ │ ├── Subscribe/
│ │ │ │ └── page.jsx
│ │ │ ├── TeamsGallery/
│ │ │ │ ├── Teams.js
│ │ │ │ └── page.jsx
│ │ │ ├── TechToolkits/
│ │ │ │ ├── page.jsx
│ │ │ │ └── techStacks.js
│ │ │ ├── TermsAndConditions/
│ │ │ │ └── page.jsx
│ │ │ ├── api/
Expand Down Expand Up @@ -178,6 +188,8 @@
│ │ ├── Hackathon.js
│ │ ├── Projects.js
│ │ ├── cpp-content.js
│ │ ├── dsa-content.js
│ │ ├── dsa-track-content.js
│ │ └── utils.js
│ └── public/
│ └── GDSC-RCIIT Logo.png
Expand Down
77 changes: 77 additions & 0 deletions src/app/(pages)/Chapters/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"use client";
import { useEffect, useState } from 'react';
import { toast } from 'react-toastify';

const ChapterTabs = () => {
const [data, setData] = useState([]);
const [activeTab, setActiveTab] = useState(null);
const [loadingToastId, setLoadingToastId] = useState(null);

useEffect(() => {
const fetchData = async () => {
const id = toast.loading('Loading data...');
setLoadingToastId(id);

try {
const response = await fetch('/api/chapters', {
method: 'GET',
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}

const result = await response.json();
setData(result);
setActiveTab(result[0]?.id || null);
toast.update(id, { render: 'Data loaded successfully!', type: 'success', isLoading: false, autoClose: 3000 });
} catch (error) {
console.error('Error fetching data:', error);
toast.update(id, { render: `Error fetching data: ${error.message}`, type: 'error', isLoading: false, autoClose: 3000 });
}
};

fetchData();
}, []);

return (
<div className="container mx-auto p-6">
<h1 className="m-2 text-5xl text-center font-extrabold bg-gradient-to-r from-blue-500 to-purple-500 text-transparent bg-clip-text">
GDSC Chapters
</h1>
<p className="text-center text-gray-500 mb-4">Global chapters</p>

<div className="flex justify-center space-x-4 border-b mb-6">
{data.map((region) => (
<button
key={region.id}
onClick={() => setActiveTab(region.id)}
className={`px-4 py-2 text-lg font-semibold transition-colors duration-300 rounded-md ${activeTab === region.id ? 'bg-blue-500 text-white' : 'text-blue-500 hover:bg-blue-100'}`}
>
{region.title}
</button>
))}
</div>

<div className="border rounded-lg p-4 bg-white shadow-lg">
<h2 className="text-2xl font-semibold text-center mb-4">Explore by region</h2>
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
{data
.find((region) => region.id === activeTab)
?.chapters.map((chapter, index) => (
<div key={index} className="flex flex-col items-center border rounded-lg p-4 bg-gray-50 shadow-md hover:shadow-xl transition-shadow duration-300">
<h3 className="font-semibold text-gray-800 text-lg mb-2">{chapter.title}</h3>
<p className="text-gray-600">{chapter.country}</p>
{/* <div className="flex items-center justify-between w-full">
{chapter.flag && (
<img src={chapter.flag} alt={`${chapter.country} flag`} className="w-10 h-6 rounded-md" />
)}
</div> */}
</div>
))}
</div>
</div>
</div>
);
};

export default ChapterTabs;
49 changes: 37 additions & 12 deletions src/app/(pages)/GeminiAI/page.jsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
"use client";
import { useState } from 'react';
import { Container, Typography, TextField, Button, Paper, Box, List, ListItem, ListItemText, Divider, IconButton } from '@mui/material';
import { useEffect, useRef, useState } from 'react';
import { Container, TextField, Button, Paper, Box, List, ListItem, ListItemText, Divider, IconButton, Stack } from '@mui/material';
import SendIcon from '@mui/icons-material/Send';
import ContentCopyIcon from '@mui/icons-material/ContentCopy';
import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';

export default function GeminiAI() {
const [userInput, setUserInput] = useState('');
const [chatHistory, setChatHistory] = useState([]);
const [chatHistory, setChatHistory] = useState(() => {
const savedHistory = localStorage.getItem('chatHistory');
return savedHistory ? JSON.parse(savedHistory) : [];
});
const chatContainerRef = useRef(null);

useEffect(() => {
localStorage.setItem('chatHistory', JSON.stringify(chatHistory));
if (chatContainerRef.current) {
chatContainerRef.current.scrollTop = chatContainerRef.current.scrollHeight;
}
}, [chatHistory]);

const formatMessage = (text) => {
const messageText = typeof text === 'string' ? text : '';
const regex = /```(.*?)```/gs;

return text.split(regex).map((part, index) =>
return messageText.split(regex).map((part, index) =>
index % 2 === 1 ? (
<Box key={index} sx={{ position: 'relative', marginBottom: '1rem' }}>
<pre style={{ whiteSpace: 'pre-wrap', backgroundColor: '#f4f4f4', padding: '0.5rem', borderRadius: '5px' }}>
Expand All @@ -22,7 +34,7 @@ export default function GeminiAI() {
<IconButton
onClick={() => {
navigator.clipboard.writeText(part);
toast.success("Copied Successfully"); // Show success toast
toast.success("Copied Successfully");
}}
size="small"
color="primary"
Expand All @@ -48,16 +60,19 @@ export default function GeminiAI() {
if (!userInput) return;

const userMessage = { sender: "User", text: userInput };
setChatHistory([...chatHistory, userMessage]);
setChatHistory((prev) => [...prev, userMessage]);
setUserInput("");

try {
const res = await fetch('/api/generate', {
const previousMessages = chatHistory.map(msg => msg.text).join("\n");
const res = await fetch('/api/generate-content', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ prompt: userInput }),
body: JSON.stringify({
prompt: "Previous Responses By You: " + previousMessages + "\nMy New Query: " + userInput
}),
});

if (!res.ok) {
Expand All @@ -72,13 +87,19 @@ export default function GeminiAI() {
}
};

const handleClearChat = () => {
setChatHistory([]);
localStorage.removeItem('chatHistory');
};

return (
<Container style={{ marginTop: '6rem', marginBottom: '2rem' }}>
<Paper elevation={3} style={{ padding: '1.5rem', borderRadius: '8px' }}>
<h1 className="m-2 text-5xl text-center font-extrabold bg-gradient-to-r from-blue-500 to-purple-500 text-transparent bg-clip-text">
Gemini AI Chat
</h1>
<Box
ref={chatContainerRef}
style={{
height: '60vh',
overflowY: 'auto',
Expand Down Expand Up @@ -121,20 +142,24 @@ export default function GeminiAI() {
</List>
</Box>
<Divider />
<form onSubmit={handleSubmit} style={{ display: 'flex', alignItems: 'center', marginTop: '1rem' }}>
<Stack direction="row" spacing={2} style={{ marginTop: '1rem' }}>
<TextField
fullWidth
variant="outlined"
value={userInput}
onChange={(e) => setUserInput(e.target.value)}
placeholder="Type a message..."
style={{ marginRight: '1rem', backgroundColor: 'white', borderRadius: '4px' }}
style={{ backgroundColor: 'white', borderRadius: '4px' }}
/>
<Button type="submit" variant="contained" color="primary" endIcon={<SendIcon />}>
<Button type="submit" variant="contained" color="primary" endIcon={<SendIcon />} onClick={handleSubmit}>
Send
</Button>
</form>
<Button variant="outlined" color="secondary" onClick={handleClearChat}>
Clear
</Button>
</Stack>
</Paper>
<ToastContainer />
</Container>
);
}
Loading
Loading