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

Position bouton profil sur la Landing #672

Merged
merged 3 commits into from
Oct 5, 2022
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
32 changes: 22 additions & 10 deletions source/sites/publicodes/Landing.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,14 @@ export default () => {
>
{emoji('👥')} En groupe
</Link>
<ProfileLink />
</div>
<NewsBanner />
</div>
</div>
{!mobile && <Illustration aira-hidden="true" />}
</div>
<ProfileLink />

{!isIframe && <LandingExplanations />}

<LandingContent background footer>
Expand Down Expand Up @@ -211,28 +212,39 @@ const ProfileLink = () => {
const { hasData } = useProfileData()
if (!hasData) return null
return (
<animate.fromTop delay="1">
<animate.appear delay="1">
<div
css={`
button {
padding: 0 0.2rem !important;
border-radius: 1rem !important;
}
display: flex;
justify-content: center;
margin-top: 1rem;
`}
>
<Link
to="/profil"
title="Page profil"
className="ui__ button plain small"
css="border-radius: 2rem !important"
className=""
css={`
width: 18rem !important;
border-radius: 2rem !important;
display: flex !important;
align-items: center !important;
`}
>
<img
aria-hidden="true"
src={openmojiURL('profile')}
css="width: 2rem"
css="width: 1.5rem"
/>
<span
css={`
margin-left: 0.5rem;
`}
>
Retrouver ma simulation
</span>
</Link>
</div>
</animate.fromTop>
</animate.appear>
)
}
2 changes: 1 addition & 1 deletion source/sites/publicodes/Personas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const PersonaGrid = ({
// the schema of peronas is not fixed yet
situation: data.situation || data,
persona: nom,
foldedSteps: data.foldedSteps || defaultMissingVariables, // If not specified, act as if all questions were answered : all that is not in the situation object is a validated default value
foldedSteps: defaultMissingVariables, // If not specified, act as if all questions were answered : all that is not in the situation object is a validated default value
})
)
}
Expand Down
71 changes: 61 additions & 10 deletions source/sites/publicodes/Profil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,61 @@ import { resetCategoryTutorials } from '../../actions/actions'
import AnswerList from '../../components/conversation/AnswerList'
import Title from '../../components/Title'
import IllustratedMessage from '../../components/ui/IllustratedMessage'
import { useEngine } from '../../components/utils/EngineContext'
import Meta from '../../components/utils/Meta'
import { ScrollToTop } from '../../components/utils/Scroll'
import { answeredQuestionsSelector } from '../../selectors/simulationSelectors'
import {
getNextQuestions,
useNextQuestions,
} from '../../components/utils/useNextQuestion'
import {
answeredQuestionsSelector,
situationSelector,
} from '../../selectors/simulationSelectors'

export const useProfileData = () => {
const answeredQuestionsLength = useSelector(answeredQuestionsSelector).length
const answeredQuestions = useSelector(answeredQuestionsSelector),
answeredQuestionsLength = answeredQuestions.length
const tutorials = useSelector((state) => state.tutorials)

const hasData = answeredQuestionsLength > 0
return { hasData, tutorials, answeredQuestionsLength }
return { hasData, tutorials, answeredQuestionsLength, answeredQuestions }
}

export default ({}) => {
const dispatch = useDispatch()
const persona = useSelector((state) => state.simulation?.persona)
const { hasData, answeredQuestionsLength, tutorials } = useProfileData()
const { hasData, answeredQuestionsLength, tutorials, answeredQuestions } =
useProfileData()
const navigate = useNavigate()
const actionChoicesLength = Object.keys(
useSelector((state) => state.actionChoices)
).length
useSelector((state) => state.actionChoices)
).length,
situation = useSelector(situationSelector)
const engine = useEngine(),
bilan = engine.evaluate('bilan')
const engineNextQuestions = getNextQuestions(
[bilan.missingVariables],
{},
[],
situation,
engine
),
nextQuestions = engineNextQuestions.filter(
(q) => !answeredQuestions.includes(q)
),
nextQuestionsLength = nextQuestions.length

const percentFinished = Math.round(
100 *
(answeredQuestionsLength /
(answeredQuestionsLength + nextQuestionsLength))
)
console.log('B4, ', bilan, nextQuestions)
const simulationStarted =
answeredQuestionsLength &&
answeredQuestionsLength > 0 &&
percentFinished < 100
return (
<div>
<Meta
Expand Down Expand Up @@ -64,8 +99,9 @@ export default ({}) => {
>
{answeredQuestionsLength > 0 && (
<p>
Vous avez répondu à {answeredQuestionsLength} questions et
choisi {actionChoicesLength} actions.{' '}
Vous avez terminé le test à {percentFinished} % (
{answeredQuestionsLength} questions) et choisi{' '}
{actionChoicesLength} actions.{' '}
</p>
)}
<details>
Expand All @@ -75,9 +111,24 @@ export default ({}) => {
<Link to="/vie-privée">En savoir plus</Link>
</details>
</div>
<div>
<div
css={`
display: flex;
flex-direction: column;
margin-top: 1rem;
`}
>
{simulationStarted && (
<Link
to="/simulateur/bilan"
className="ui__ button plain"
css="margin: 0"
>
{emoji('▶️')} Finir mon test
</Link>
)}
<button
className="ui__ button plain"
className={`ui__ button ${!simulationStarted ? 'plain' : ''}`}
css="margin: 1rem 0"
onClick={() => {
dispatch(resetSimulation())
Expand Down