Skip to content
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules/
client/node_modules/
server/node_modules/
__pycache__/
*.pyc
*.pyo
35 changes: 28 additions & 7 deletions client/src/Dashboard.jsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
import React, { useState, useEffect } from "react";
import { useState, useEffect } from "react";
import { getBalance, transferMoney } from "./api";
import LoadingSpinner from "./components/LoadingSpinner";

function Dashboard() {
const [balance, setBalance] = useState(0);
const [to, setTo] = useState("");
const [amount, setAmount] = useState("");
const [loading, setLoading] = useState(true);
const [transferring, setTransferring] = useState(false);

useEffect(() => {
loadBalance();
}, []);

const loadBalance = async () => {
setLoading(true);
const data = await getBalance();
setBalance(data.balance);
setLoading(false);
};

const handleTransfer = async () => {
setTransferring(true);
const data = await transferMoney(to, amount);
alert(data.message);
loadBalance();
await loadBalance();
setTransferring(false);
};

const logout = () => {
Expand All @@ -29,17 +36,31 @@ function Dashboard() {
return (
<div>
<h2>Dashboard</h2>
<h3>Balance: ₹{balance}</h3>

{loading ? (
<LoadingSpinner />
) : (
<h3>Balance: ₹{balance}</h3>
)}

<h3>Transfer Money</h3>
<input placeholder="Recipient Username" onChange={e => setTo(e.target.value)} />
<input placeholder="Amount" type="number" onChange={e => setAmount(e.target.value)} />
<button onClick={handleTransfer}>Send</button>
<input
placeholder="Recipient Username"
onChange={e => setTo(e.target.value)}
/>
<input
placeholder="Amount"
type="number"
onChange={e => setAmount(e.target.value)}
/>
<button onClick={handleTransfer} disabled={transferring}>
{transferring ? 'Sending…' : 'Send'}
</button>

<br /><br />
<button onClick={logout}>Logout</button>
</div>
);
}

export default Dashboard;
export default Dashboard;
5 changes: 5 additions & 0 deletions client/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export const getBalance = async () => {
return res.json();
};

export const getPosts = async () => {
const res = await fetch(`${API_URL}/api/posts`);
return res.json();
};

export const transferMoney = async (to, amount) => {
const token = localStorage.getItem("token");
const res = await fetch(`${API_URL}/api/transfer`, {
Expand Down
9 changes: 9 additions & 0 deletions client/src/components/LoadingSpinner.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import styles from './LoadingSpinner.module.css';

export default function LoadingSpinner() {
return (
<div className={styles.wrapper}>
<div className={styles.spinner} role="status" aria-label="Loading" />
</div>
);
}
21 changes: 21 additions & 0 deletions client/src/components/LoadingSpinner.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.wrapper {
display: flex;
justify-content: center;
align-items: center;
padding: 2rem;
}

.spinner {
width: 40px;
height: 40px;
border: 4px solid #e0e0e0;
border-top-color: #333;
border-radius: 50%;
animation: spin 0.75s linear infinite;
}

@keyframes spin {
to {
transform: rotate(360deg);
}
}
39 changes: 35 additions & 4 deletions client/src/pages/Home.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,41 @@
import React from 'react';
import { useState, useEffect } from "react";
import { getPosts } from "../api";
import LoadingSpinner from "../components/LoadingSpinner";

function Home() {
const [posts, setPosts] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);

useEffect(() => {
getPosts()
.then((data) => setPosts(data || []))
.catch(() => setError("Failed to load posts."))
.finally(() => setLoading(false));
}, []);

return (
<div>
<h1 className="red-bordered-heading">Welcome to DevStations E-Learning Platform</h1>
</div>
<div style={{ padding: "1rem 2rem" }}>
<h1 className="red-bordered-heading">
Welcome to DevStations E-Learning Platform
</h1>

{loading && <LoadingSpinner />}

{error && <p style={{ color: "red" }}>{error}</p>}

{!loading && !error && posts.length === 0 && <p>No posts yet.</p>}

{posts.map((post) => (
<div
key={post.id}
style={{ borderBottom: "1px solid #ddd", padding: "1rem 0" }}
>
<h2 style={{ margin: "0 0 0.25rem" }}>{post.title}</h2>
<p style={{ margin: 0, color: "#555" }}>{post.body}</p>
</div>
))}
</div>
);
}

Expand Down