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

45 domande immagini categorie #50

Merged
merged 33 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e100ffb
Create classi Question e il suo enum
fmanto01 Sep 25, 2024
c181369
tie
pesto13 Sep 28, 2024
923759e
Aggiunte 4 immagini
fmanto01 Sep 28, 2024
437b75c
Sistemato margine
fmanto01 Sep 28, 2024
5a8c5a5
Merge branch 'backend-for-new-questions' into 45-domande-immagini-cat…
pesto13 Sep 29, 2024
7a1d855
creazione questionGenre e QuestionMode
pesto13 Sep 29, 2024
f373962
sistemato backend
pesto13 Sep 29, 2024
c9a6eba
finire di completare la page per images
pesto13 Sep 29, 2024
278c062
punto di partenza
pesto13 Sep 29, 2024
444153e
rifatto il login tamite api github
pesto13 Sep 29, 2024
ef9867c
aggiunte transition "automatiche"
pesto13 Sep 29, 2024
340ef4f
Merge pull request #47 from Cleo-Tech/pesto_45domande
pesto13 Sep 29, 2024
4da5129
Merge branch 'preprod' into 45-domande-immagini-categorie
pesto13 Sep 29, 2024
e7f1e2a
allineato il termine categoria con genere
pesto13 Sep 29, 2024
057063a
Separato componente
fmanto01 Sep 29, 2024
02a63a5
Merge branch '45-domande-immagini-categorie' of https://github.com/Cl…
fmanto01 Sep 29, 2024
47672f0
rimosso forzatura di foto
pesto13 Sep 29, 2024
3feb7d1
Merge branch '45-domande-immagini-categorie' of https://github.com/Cl…
pesto13 Sep 29, 2024
3a6ec0b
leggibilita urls
pesto13 Sep 29, 2024
1cdae8e
Controllo immagini nel voto
fmanto01 Sep 30, 2024
d11d22f
fixato problema doppio enter
pesto13 Oct 1, 2024
387a3c6
fix gameflow
pesto13 Oct 1, 2024
0083e81
rimosse robe inutili
pesto13 Oct 1, 2024
4097c9e
qustion prende il valore di un name se serve (nelle foto)
pesto13 Oct 4, 2024
20f0623
sul backend vengono salvate le immagini
pesto13 Oct 4, 2024
e839518
aaa
pesto13 Oct 4, 2024
9bfb649
Shuffle immagini
fmanto01 Oct 4, 2024
4505e61
Aggiunte domande photo
fmanto01 Oct 4, 2024
fd627b7
sistemati i nomi delle immagini
pesto13 Oct 4, 2024
0593d9c
Merge branch '45-domande-immagini-categorie' of https://github.com/Cl…
pesto13 Oct 4, 2024
b0b25db
config sistemate
pesto13 Oct 4, 2024
4f2a3c9
fix errori lint
pesto13 Oct 4, 2024
6e4bf8c
sistemato include
pesto13 Oct 4, 2024
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
24 changes: 24 additions & 0 deletions Scoprimi/public/css/login.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@
transition: transform 0.2s ease-in-out, border-color 0.2s;
}

/* Stile delle immagini */

.image-question {
width: calc(50% - 0.5rem);
/* Occupano metà della larghezza, meno il margine */
height: 50%;
/* Imposta l'altezza al 50% del contenitore */
margin-bottom: 1rem;
/* Margine inferiore per lo spazio tra le righe */
object-fit: cover;
/* Ritaglia l'immagine per riempire il contenitore */
border-radius: 10px;
/* Arrotonda i bordi delle immagini */
}

/* Hover su immagini */
.image-thumbnail:hover {
transform: scale(1.1);
Expand All @@ -38,4 +53,13 @@
/* Immagine selezionata */
.selected {
border: 3px solid var(--tertiary-color);
}

.elegant-background-images {
display: flex;
flex-wrap: wrap;
/* Permette alle immagini di andare a capo */
justify-content: space-between;
/* Spazio tra le immagini */
/* Margine attorno al contenitore */
}
Binary file added Scoprimi/public/snikerts.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 49 additions & 25 deletions Scoprimi/src/components/game/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import PlayerList from './PlayerList';
import { useSession } from '../../contexts/SessionContext';
import Results from './Results';
import { GameStates, useGameState } from '../../contexts/GameStateContext';
import ImageList from './ImageList';
import { QuestionMode } from '../../../../Server/src/data/Question';

const Game: React.FC = () => {
const [question, setQuestion] = useState<string>('');
Expand All @@ -23,10 +25,12 @@ const Game: React.FC = () => {
const [resetSelection, setResetSelection] = useState<boolean>(false);
const [buttonClicked, setButtonClicked] = useState<boolean>(false); // Nuovo stato per il bottone
const [playersWhoVoted, setPlayersWhoVoted] = useState<string[]>([]); //non è come il server, questo è un array e bona
const [questionImages, setQuestionImages] = useState<string[]>([]);

const { currentLobby, currentPlayer, setCurrentLobby } = useSession();
const { actualState, transitionTo } = useGameState();
const { actualState, transitionTo, fromQuestionToResponse, fromNextQuestionToQuestion } = useGameState();
const navigate = useNavigate();
const [isPhoto, setIsPhoto] = useState<boolean>(false);

// Questo viene fatto solo 1 volta e amen
useEffect(() => {
Expand All @@ -36,20 +40,21 @@ const Game: React.FC = () => {

useEffect(() => {
socket.on(c.SEND_QUESTION, ({ question, players, images }: QuestionData) => {
console.log('ciaoooo');
console.log(question, players, images);
setClicked(false);
setIsTimerActive(true);
setQuestion(question);
setQuestion(question.text);
setPlayers(players);
setImages(images);
setResetSelection(false);
setButtonClicked(false);
setPlayersWhoVoted([]);
// TODO controlla tipo di domanda (metto generic perche ora ho solo questo)
transitionTo(GameStates.GENERICQUESTION);
fromNextQuestionToQuestion(question.mode);
setQuestionImages(question.images);
// TODO fix veloce per 2 pagine di show_result
setIsPhoto(question.mode === QuestionMode.Photo);
});
}, [transitionTo]);
}, [fromNextQuestionToQuestion]);


useEffect(() => {
Expand Down Expand Up @@ -109,8 +114,10 @@ const Game: React.FC = () => {
setClicked(true);
setIsTimerActive(false);
socket.emit(c.VOTE, { lobbyCode: currentLobby, voter: currentPlayer, vote: player });
fromQuestionToResponse();
};


const handleNextQuestion = () => {
setResetSelection(true);
setButtonClicked(true); // Cambia lo stato del bottone
Expand All @@ -121,37 +128,48 @@ const Game: React.FC = () => {
const handleTimeUp = () => {
if (!clicked) {
socket.emit(c.VOTE, { lobbyCode: currentLobby, voter: currentPlayer, vote: '' });
transitionTo(GameStates.GENERICRESPONSE);
fromQuestionToResponse();
}
setIsTimerActive(false);
};

function getRandomInt(min: number, max: number) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}

const selectPlayer = () => players.at(getRandomInt(0, players.length - 1));

// Render delle page
switch (actualState) {

// case GameStates.NEXTQUESTION:
// break;
// case GameStates.GENERICRESPONSE:
// break;
case GameStates.PERCULARE:
case GameStates.MOCK:
break;
case GameStates.WHORESPONSE:
case GameStates.WHOQUESTION:
break;
return (
<div className="paginator">
<Question question={question} selectedPlayer={selectPlayer} />
<div className='inline'>
<div className='label-container'>
<p>Scegli un giocatore</p>
</div>
<Timer duration={25} onTimeUp={handleTimeUp} isActive={isTimerActive} />
</div>
<ImageList images={questionImages} onVote={handleVote} disabled={clicked} resetSelection={resetSelection} />
</div>
);
case GameStates.THEMEQUESTION:
break;
case GameStates.THEMERESPONSE:
break;
case GameStates.WHORESPONSE:
break;
case GameStates.THEMERESULTFINAL:
break;

case GameStates.GENERICQUESTION:
case GameStates.GENERICRESPONSE:
case GameStates.STANDARDQUESTION:
case GameStates.STANDARDRESPONSE:
return (
<div className="paginator">
<Question question={question} />
<Question question={question} selectedPlayer={selectPlayer} />
<div className='inline'>
<div className='label-container'>
<p>Scegli un giocatore</p>
Expand All @@ -170,15 +188,21 @@ const Game: React.FC = () => {
<div className="paginator">
<div className="result-message text-center">
{mostVotedPerson === '' ? (<h3>Pareggio!</h3>) : (<h3>Persona più votata</h3>)}
<img
src={playerImages[mostVotedPerson]}
alt={mostVotedPerson}
className="winnerImage"
/>
<p>{mostVotedPerson}</p>
{!isPhoto ?
<img
src={playerImages[mostVotedPerson]}
alt={mostVotedPerson}
className="winnerImage"
/> :
<img
src={mostVotedPerson}
alt={mostVotedPerson.substring(mostVotedPerson.lastIndexOf('/') + 1).split('.')[0]}
className="winnerImage"
/>}
<p>{mostVotedPerson.substring(mostVotedPerson.lastIndexOf('/') + 1).split('.')[0]}</p>
</div>
<div className='elegant-background image-container fill scrollable'>
<Results mostVotedPerson={mostVotedPerson} playerImages={playerImages} voteRecap={voteRecap} />
<Results mostVotedPerson={mostVotedPerson} playerImages={playerImages} voteRecap={voteRecap} isPhoto={isPhoto} />
</div>
<div className="d-flex justify-content-center align-items-center">
<button
Expand Down
41 changes: 41 additions & 0 deletions Scoprimi/src/components/game/ImageList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React, { useState, useEffect } from 'react';

interface ImageListProps {
images: string[];
onVote: (player: string) => void;
disabled: boolean;
resetSelection: boolean;
}

const ImageList: React.FC<ImageListProps> = ({ images, onVote, disabled, resetSelection }) => {
const [clicked, setClicked] = useState(false);

useEffect(() => {
if (resetSelection) {
setClicked(false);
}
}, [resetSelection]);

const handlePlayerClick = (imageUrl: string) => {
if (!disabled) {
onVote(imageUrl);
}
};

return (
<div className='elegant-background-images fill'>
{images.map((imageUrl, index) => (
<img
key={index}
src={imageUrl}
className='image-question'
alt={`image-${index}`}
onClick={() => handlePlayerClick(imageUrl)}
style={{ cursor: clicked || disabled ? 'not-allowed' : 'pointer', opacity: clicked || disabled ? 0.5 : 1 }}
/>
))}
</div>
);
};

export default ImageList;
3 changes: 0 additions & 3 deletions Scoprimi/src/components/game/PlayerList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useState, useEffect } from 'react';
import { GameStates, useGameState } from '../../contexts/GameStateContext';

interface PlayerListProps {
players: string[]
Expand All @@ -12,7 +11,6 @@ interface PlayerListProps {

const PlayerList: React.FC<PlayerListProps> = ({ players, images, onVote, disabled, resetSelection, playersWhoVoted }) => {
const [selectedPlayer, setSelectedPlayer] = useState<string | null>(null);
const { transitionTo } = useGameState();
useEffect(() => {
if (resetSelection) {
setSelectedPlayer(null); // Resetta la selezione quando `resetSelection` è vero
Expand All @@ -23,7 +21,6 @@ const PlayerList: React.FC<PlayerListProps> = ({ players, images, onVote, disabl
if (!disabled) {
setSelectedPlayer(player);
onVote(player);
transitionTo(GameStates.GENERICRESPONSE);
}
};

Expand Down
7 changes: 5 additions & 2 deletions Scoprimi/src/components/game/Question.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import React from 'react';

interface QuestionProps {
question: string;
selectedPlayer: () => string;
}

const Question: React.FC<QuestionProps> = ({ question }) => (
const placeholderChar = '$';

const Question: React.FC<QuestionProps> = ({ question, selectedPlayer }) => (
<div id="questionContainer">
<h4 id="question">{question}</h4>
<h4 id="question">{question.replace(placeholderChar, selectedPlayer)}</h4>
</div>
);

Expand Down
9 changes: 7 additions & 2 deletions Scoprimi/src/components/game/Results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ interface ResultsProps {
voteRecap: { [key: string]: string };
playerImages: { [key: string]: string };
mostVotedPerson: string;
isPhoto: boolean;
}

const Results: React.FC<ResultsProps> = ({ voteRecap, playerImages, mostVotedPerson }) => (
const todoShitFunction = (votestring: string) =>
votestring.substring(votestring.lastIndexOf('/') + 1).split('.')[0];


const Results: React.FC<ResultsProps> = ({ voteRecap, playerImages, mostVotedPerson, isPhoto }) => (
<div id="resultsContainer" className="text-center">
<div id="resultMessageContainer">
{
Expand All @@ -25,7 +30,7 @@ const Results: React.FC<ResultsProps> = ({ voteRecap, playerImages, mostVotedPer
<span
className={`status-pill-vote ${mostVotedPerson === vote ? 'my-bg-success' : 'my-bg-error'}`}
>
{vote}
{isPhoto ? todoShitFunction(vote) : vote}
</span>
</div>
)}
Expand Down
Loading