setsubdomain page & fix scoll in dashboard

This commit is contained in:
AntoninoP 2024-09-21 10:08:01 +02:00
parent 3c428b89b6
commit 55202271c8
6 changed files with 155 additions and 32 deletions

View File

@ -1,6 +1,8 @@
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import styles from './serverCard.module.scss'; import styles from './serverCard.module.scss';
import paper from '../../assets/frameworks/paper.png'; import paper from '../../assets/frameworks/paper.png';
import fabric from '../../assets/frameworks/fabric.png';
import forge from '../../assets/frameworks/forge.png';
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { FaTrash } from 'react-icons/fa'; import { FaTrash } from 'react-icons/fa';
@ -8,6 +10,12 @@ const ServerCard = ({ status, version, name, framework, onRunClick, onStopClick,
const getFrameworkSource = () => { const getFrameworkSource = () => {
switch (framework) { switch (framework) {
case 'frabric':
return fabric;
case 'forge':
return forge;
case 'bedrock':
return paper;
default: default:
return paper; return paper;
} }
@ -53,9 +61,6 @@ const ServerCard = ({ status, version, name, framework, onRunClick, onStopClick,
<div className={styles.version}>Version: {version}</div> <div className={styles.version}>Version: {version}</div>
</div> </div>
</div> </div>
<div className={styles.status}>
{status ? `${countPlayers}/${maxPlayers} joueurs` : " "}
</div>
</div> </div>
<div className={styles.actions}> <div className={styles.actions}>
<div> <div>
@ -77,6 +82,9 @@ const ServerCard = ({ status, version, name, framework, onRunClick, onStopClick,
</button> </button>
)} )}
</div> </div>
<div className={styles.status}>
{status ? `${countPlayers}/${maxPlayers} joueurs` : " "}
</div>
</div> </div>
<FaTrash <FaTrash
className={styles.trashIcon} className={styles.trashIcon}

View File

@ -23,10 +23,10 @@
.favoriteserverCard{ .favoriteserverCard{
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: space-between; justify-content: space-around;
align-items: flex-start; align-items: center;
width: 30rem; width: 38.5rem;
padding: 3rem; padding: 3rem 0rem 3rem 3rem;
border: 0.1rem solid black; border: 0.1rem solid black;
border-radius: 0.8rem; border-radius: 0.8rem;
margin-bottom: 3rem; margin-bottom: 3rem;
@ -78,7 +78,7 @@
} }
.serverName { .serverName {
font-size: 1.6rem; font-size: 1.5rem;
font-weight: bold; font-weight: bold;
} }
@ -103,8 +103,8 @@
} }
.startStopButton { .startStopButton {
padding: 1rem 1.8rem; padding: 1rem 1.5rem;
border-radius: 0.6rem; border-radius: 0.5rem;
border: none; border: none;
color: white; color: white;
cursor: pointer; cursor: pointer;

View File

@ -18,7 +18,7 @@ const Bedrock = ({ user }) => {
onBackClick={() => navigate('/CreateServer')} onBackClick={() => navigate('/CreateServer')}
/> />
<div className={styles.hey}> <div className={styles.hey}>
<h1> bedrock</h1> <h1> Prochainement disponible</h1>
</div> </div>
</div> </div>
); );

View File

@ -18,7 +18,7 @@ const Modpack = ({ user }) => {
onBackClick={() => navigate('/CreateServer')} onBackClick={() => navigate('/CreateServer')}
/> />
<div className={styles.hey}> <div className={styles.hey}>
<h1> modpack</h1> <h1>Prochainement disponible</h1>
</div> </div>
</div> </div>
); );

View File

@ -14,8 +14,8 @@ const DashboardPage = ({ user }) => {
const [servers, setServers] = useState([]); const [servers, setServers] = useState([]);
const [subdomain, setSubdomain] = useState(null); const [subdomain, setSubdomain] = useState(null);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [showCreateServer, setShowCreateServer] = useState(false);
const [searchTerm, setSearchTerm] = useState(''); const [searchTerm, setSearchTerm] = useState('');
const [newSubdomain, setNewSubdomain] = useState('');
const loadServers = useCallback(async () => { const loadServers = useCallback(async () => {
try { try {
@ -39,7 +39,7 @@ const DashboardPage = ({ user }) => {
loadServers(); loadServers();
}, [loadServers]); }, [loadServers]);
const handleCreateServerPage = () => setShowCreateServer(true); const handleCreateServer = () => navigate('/CreateServer');
const handleRunServer = async (serverName) => { const handleRunServer = async (serverName) => {
try { try {
@ -73,8 +73,21 @@ const DashboardPage = ({ user }) => {
navigator.clipboard.writeText(address); navigator.clipboard.writeText(address);
}; };
const handleSaveSubdomain = async () => {
try {
const response = await serviiApi.setSubdomain(newSubdomain);
if (response.success) {
setSubdomain(newSubdomain);
loadServers();
} else {
console.error('Erreur lors de la création du sous-domaine');
}
} catch (error) {
console.error('Erreur lors de la création du sous-domaine:', error);
}
};
const favoriteServer = servers[0] || null; const favoriteServer = servers[0] || null;
const serversWithoutFavorite = servers.filter(server => server !== favoriteServer); const serversWithoutFavorite = servers.filter(server => server !== favoriteServer);
if (loading) { if (loading) {
@ -86,21 +99,58 @@ const DashboardPage = ({ user }) => {
); );
} }
if (!subdomain) {
return (
<div className={styles.welcomeContainer}>
<h1 className={styles.welcomeMessage}>
Bienvenue, {user?.displayName || ' '} !
</h1>
<p className={styles.subdomainMessage}>
Le sous-domaine est le nom sous lequel vos amis et vous rejoignez le serveur. Choisissez-le bien, car il n'est pas facilement modifiable !
</p>
<div className={styles.subdomainInputContainer}>
<input
type="text"
placeholder="Saisissez un nom de domaine"
value={newSubdomain}
onChange={(e) => setNewSubdomain(e.target.value)}
className={styles.subdomainInput}
onKeyPress={(e) => e.key === 'Enter' && handleSaveSubdomain()}
/>
<button className={styles.btnCreate} onClick={handleSaveSubdomain}>
Envoyer
</button>
</div>
</div>
);
}
if (servers.length === 0) {
return (
<div className={styles.dashboardContainer}>
<Navbar user={user} />
<div className={styles.mainContent}>
<button className={styles.btnCreate} onClick={handleCreateServer}>
<div className={styles.plusIcon}>+</div>
Créer un nouveau serveur
</button>
</div>
</div>
);
}
return ( return (
<div className={styles.dashboardContainer}> <div className={styles.dashboardContainer}>
<Navbar user={user} /> <Navbar user={user} />
{showCreateServer ? (
navigate('/CreateServer')
) : (
<div className={styles.mainContent}> <div className={styles.mainContent}>
<div className={styles.iptitle}> <div className={styles.iptitle}>
Adresse de connexion à vos serveurs : Adresse de connexion à vos serveurs :
<span onClick={handleCopyAddress} className={styles.subdomain}> <span onClick={handleCopyAddress} className={styles.subdomain}>
{" " + subdomain}.servii.fr {" " + subdomain}.servii.fr
</span> </span>
</div> </div>
<div className={styles.headerContainer}> <div className={styles.headerContainer}>
<input <input
type="text" type="text"
@ -109,7 +159,7 @@ const DashboardPage = ({ user }) => {
onChange={(e) => setSearchTerm(e.target.value)} onChange={(e) => setSearchTerm(e.target.value)}
className={styles.searchInput} className={styles.searchInput}
/> />
<button className={styles.btnCreate} onClick={handleCreateServerPage}> <button className={styles.btnCreate} onClick={handleCreateServer}>
<div className={styles.plusIcon}>+</div> <div className={styles.plusIcon}>+</div>
<div>Créer un nouveau serveur</div> <div>Créer un nouveau serveur</div>
</button> </button>
@ -133,10 +183,9 @@ const DashboardPage = ({ user }) => {
favoriteServer={true} favoriteServer={true}
/> />
</div> </div>
) : ( ) : null}
<p className={styles.AllserversTitle}>Aucun serveur disponible</p>
)}
</div> </div>
<div className={styles.cardsContainer}> <div className={styles.cardsContainer}>
{serversWithoutFavorite.length > 0 ? ( {serversWithoutFavorite.length > 0 ? (
serversWithoutFavorite.filter(server => serversWithoutFavorite.filter(server =>
@ -156,18 +205,13 @@ const DashboardPage = ({ user }) => {
subdomain={subdomain} subdomain={subdomain}
/> />
)) ))
) : ( ) : null}
<p className={styles.noServerText}>Aucun serveur trouvé</p>
)}
</div> </div>
</div> </div>
)}
</div> </div>
); );
}; };
DashboardPage.propTypes = { DashboardPage.propTypes = {
user: PropTypes.shape({ user: PropTypes.shape({
uid: PropTypes.string.isRequired, uid: PropTypes.string.isRequired,

View File

@ -15,7 +15,7 @@ html, body {
} }
.mainContent { .mainContent {
width: 100%; width: 90%;
padding: 2.5rem; padding: 2.5rem;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -35,7 +35,7 @@ html, body {
border-radius: 8px; border-radius: 8px;
padding: .8rem 1rem; padding: .8rem 1rem;
font-size: 1.25rem; font-size: 1.25rem;
width: 10rem; width: 16rem;
flex: none; flex: none;
} }
@ -85,3 +85,74 @@ html, body {
color: var(--text-color); color: var(--text-color);
margin: 1rem 0; margin: 1rem 0;
} }
.welcomeContainer {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin-top: 4rem;
padding: 2rem;
background-color: #f7f7f7;
border-radius: 0.5rem;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
.welcomeMessage {
font-size: 2.5rem;
font-weight: 600;
color: #333;
margin-bottom: 1rem;
}
.subdomainMessage {
font-size: 1.2rem;
color: #666;
margin-bottom: 2rem;
text-align: center;
max-width: 50rem;
}
.subdomainInputContainer {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
gap: .25rem;
}
.subdomainInput {
padding: 0.75rem 1rem;
border-radius: 0.5rem;
border: 1px solid #ccc;
font-size: 1.25rem;
width: 20rem;
}
.btnCreateSubdomain {
display: flex;
justify-content: center;
align-items: center;
background-color: #2f2f2f;
border: none;
padding: .5rem 1rem;
cursor: pointer;
font-size: 1rem;
font-weight: 600;
border-radius: 0.5rem;
color: white;
transition: background-color 0.3s ease;
margin-left: 1rem;
display: flex;
justify-content: center;
align-items: center;
background-color: #2f2f2f;
border: none;
padding: 0.75rem 1.5rem;
cursor: pointer;
font-size: 1rem;
font-weight: 600;
border-radius: 0.5rem;
color: white;
transition: background-color 0.3s ease;
}