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

Pix 15834 display popup for smarphones and vertical tablets #11041

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
130 changes: 130 additions & 0 deletions junior/app/components/device-warning-modal.gjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import trapFocus from '@1024pix/pix-ui/app/modifiers/trap-focus';
import PixButton from '@1024pix/pix-ui/components/pix-button';
import PixButtonLink from '@1024pix/pix-ui/components/pix-button-link';
import { action } from '@ember/object';
import { service } from '@ember/service';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { t } from 'ember-intl';

import { types } from '../services/device';
const { MOBILE, TABLET } = types;

export default class DeviceWarningModal extends Component {
@tracked showModal = false;
@tracked deviceType = '';
@tracked orientation = '';
@service device;
@service intl;
@service currentLearner;

shouldDisplayModal() {
const { type, orientation } = this.device.info;
this.deviceType = type;
this.orientation = orientation;

if (this.deviceType === MOBILE) {
return true;
}

const shouldDisplay = type === TABLET && orientation.startsWith('portrait');

if (!shouldDisplay && this.showModal) {
this.currentLearner.setHasSeenWarningModal();
} else if (this.currentLearner.hasSeenWarningModal) {
return false;
}

return shouldDisplay;
}

constructor() {
super(...arguments);
if (this.shouldDisplayModal()) {
this.showModal = true;
}

screen.orientation.addEventListener('change', () => {
this.showModal = this.shouldDisplayModal();
});
}

@action
onCloseModal() {
this.currentLearner.setHasSeenWarningModal();
this.showModal = false;
}

get title() {
return this.intl.t(`components.device-warning-modal.${this.deviceType}.title`);
}

get contentText() {
return this.intl.t(`components.device-warning-modal.${this.deviceType}.subtitle`);
}

get isTablet() {
return this.deviceType === TABLET;
}

get isMobile() {
return this.deviceType === MOBILE;
}

get modalClassName() {
if (this.deviceType === TABLET) {
return 'device-warning-modal is-tablet';
}

if (this.deviceType === MOBILE && this.orientation.startsWith('landscape')) {
return 'device-warning-modal is-landscape';
}

return 'device-warning-modal';
}
<template>
<div
class="device-warning-modal-overlay {{unless this.showModal ' device-warning-modal-overlay--hidden'}}"
{{trapFocus this.showModal}}
>
<div class={{this.modalClassName}} role="dialog">
{{#if this.isTablet}}
<PixButton
class="close-button"
@iconBefore="close"
@triggerAction={{this.onCloseModal}}
@ariaLabel="Fermer"
@size="small"
@variant="secondary"
>
{{t "common.actions.close"}}
</PixButton>
{{/if}}

<section>
<img src="/images/logo-in-one-line.svg" alt="Pix Junior" class="logo" />
<h1>
{{this.title}}
</h1>
<span>
{{#if this.isTablet}}
<img
src="/images/icons/screen-rotation.svg"
alt=""
aria-describedby="device-warning-modal-text-content"
/>
{{/if}}
<h2 id="device-warning-modal-text-content">
{{this.contentText}}
</h2>
</span>
{{#if this.isMobile}}
<PixButtonLink class="button-link" @href="https://pix.fr/enseignement-primaire">
{{t "components.device-warning-modal.button.label"}}
</PixButtonLink>
{{/if}}
</section>
</div>
</div>
</template>
}
13 changes: 11 additions & 2 deletions junior/app/services/current-learner.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@ export default class CurrentLearnerService extends Service {
return JSON.parse(localStorage.getItem('learner'));
}

async setLearner(learner) {
setLearner(learner) {
localStorage.setItem('learner', JSON.stringify(learner));
}

async remove() {
setHasSeenWarningModal() {
localStorage.setItem('learner-has-seen-warning-modal', 'true');
}

get hasSeenWarningModal() {
return !!localStorage.getItem('learner-has-seen-warning-modal');
}

remove() {
localStorage.removeItem('learner');
localStorage.removeItem('learner-has-seen-warning-modal');
}
}
41 changes: 41 additions & 0 deletions junior/app/services/device.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import Service from '@ember/service';

const MOBILE_MAX_HEIGHT = 720;
const MOBILE_MAX_WIDTH = 540;
const TABLET_MAX_HEIGHT = 1366;
const TABLET_MAX_WIDTH = 1024;

export const types = {
DESKTOP: 'desktop',
MOBILE: 'mobile',
TABLET: 'tablet',
};

export default class DeviceService extends Service {
get info() {
return {
orientation: screen.orientation.type,
type: this.getType(screen.orientation.type),
};
}

getType(orientation) {
if (orientation.startsWith('landscape')) {
if (screen.width >= TABLET_MAX_HEIGHT) {
return types.DESKTOP;
}
if (screen.width >= MOBILE_MAX_HEIGHT && screen.height >= MOBILE_MAX_WIDTH) {
return types.TABLET;
}
return types.MOBILE;
} else {
if (screen.width >= TABLET_MAX_WIDTH) {
return types.DESKTOP;
}
if (screen.width >= MOBILE_MAX_WIDTH) {
return types.TABLET;
}
return types.MOBILE;
}
}
}
1 change: 1 addition & 0 deletions junior/app/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@import 'components/challenge/content/challenge-media';
@import 'components/challenge/challenge-layout';
@import 'components/delayed-element';
@import 'components/device-warning-modal';
@import 'components/mission-card/card';
@import 'components/bubble';
@import 'components/footer';
Expand Down
93 changes: 93 additions & 0 deletions junior/app/styles/components/device-warning-modal.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
.device-warning-modal-overlay {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 1000;
background-color: var(--pix-neutral-0);

&--hidden {
visibility: hidden;
opacity: 0;
}
}

.device-warning-modal {
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
text-align: initial;
background-image: url('/images/background-blob-with-robot.svg');
background-repeat: no-repeat;
background-position-x: right;
background-position-y: bottom;
background-size: 90%;
background-attachment: fixed;

.close-button {
align-self: self-end;
margin: var(--pix-spacing-8x) var(--pix-spacing-8x) 0 0;
}

section {
display: flex;
flex-direction: column;
gap: var(--pix-spacing-6x);
margin: var(--pix-spacing-12x) var(--pix-spacing-9x);
color: var(--pix-neutral-900);

h1 {
font-weight: 800;
font-size: 1.2rem;
}

h2 {
font-weight: 500;
font-size: 1.2rem;
}

span {
display: flex;
flex-direction: row;
gap: var(--pix-spacing-6x);
align-items: center;
}

.logo {
width: 182px;
height: 50px;
}

.button-link {
max-width: 200px;
}
}

&.is-landscape {
background-size: 45%;

section {
max-width: 52%;
}
}

&.is-tablet section {
margin: var(--pix-spacing-6x) 80px;

h1 {
font-size: 2.5rem;
}

h2 {
font-size: 1.5rem;
}

.logo {
width: 291px;
height: 80px;
margin-bottom: var(--pix-spacing-3x);
}
}
}
1 change: 1 addition & 0 deletions junior/app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{{page-title (t "pages.pix-junior")}}
<div class="app">
<DeviceWarningModal />
<Banner::Communication />
<main>
{{outlet}}
Expand Down
5 changes: 5 additions & 0 deletions junior/public/images/icons/screen-rotation.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions junior/translations/fr.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"common": {
"actions": {
"close": "Fermer"
}
},
"components": {
"challenge": {
"embed-simulator": {
Expand All @@ -7,6 +12,20 @@
}
}
},
"device-warning-modal": {
"button": {
"label": "Découvrir Pix Junior"
},
"mobile": {
"subtitle": "Merci d'utiliser Pix Junior sur une tablette ou un ordinateur.",
"title": "Cette résolution n’est pas prise en compte."
},
"tablet": {
"subtitle": "Tourne ta tablette pour commencer à utiliser Pix Junior.",
"title": "Oups, ta tablette n'est pas dans le bon sens..."
},
"title": "Écran dans le mauvais sens"
},
"oralization-button": {
"label": "Lire la consigne à haute voix",
"play": "J'écoute",
Expand Down
Loading