Skip to content

Commit

Permalink
Get chapters based on person id (user role)
Browse files Browse the repository at this point in the history
  • Loading branch information
cs1m0n committed Apr 16, 2024
1 parent b1fbdd8 commit 449cbcc
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 50 deletions.
9 changes: 6 additions & 3 deletions src/Experience/Experience.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import World from './World/World.js'
import FAQ from './Components/FAQ.js'
import _gl from './Utils/Globals.js'
import _lang from './Utils/Lang.js'
import _e from './Utils/Events.js'

let instance = null

Expand All @@ -34,10 +35,12 @@ export default class Experience {
this.sizes = new Sizes()
this.time = new Time()
this.scene = new THREE.Scene()
this.resources = new Resources(sources)
this.pointer = new MouseMove()
this.world = new World()
this.auth0 = {}

document.addEventListener(_e.ACTIONS.USER_DATA_FETCHED, () => {
this.resources = new Resources(sources)
this.world = new World()
})

// Time animation event
this.videoIsPlaying = false
Expand Down
2 changes: 1 addition & 1 deletion src/Experience/Utils/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const wpApiUrl_staging = 'https://staging-bcckids.kinsta.cloud/wp-json'
const wpApiUrl_local = 'https://bcckids.local/wp-json'
const wpApiUrl = getWpApiUrl()

const getBiexChapters = () => wpApiUrl + '/biex-chapters/get?lang=' + _lang.getLanguageCode()
const getBiexChapters = (personId) => wpApiUrl + '/biex-chapters/get?lang=' + _lang.getLanguageCode() + '&personId=' + personId
const getRoles = (personId) => wpApiUrl_production + '/roles/' + personId
const saveAnswer = () => wpApiUrl + '/answer/save'
const getAppDownloadLinks = () => wpApiUrl + '/app/download-links/get'
Expand Down
3 changes: 0 additions & 3 deletions src/Experience/Utils/Notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ let notification = []

export default class Notification {
constructor(text, icon = '') {
this.experience = new Experience()
this.program = this.experience.world.program

this.htmlEl = document.createElement('div')
this.htmlEl.className = 'isolate fixed grid place-content-center inset-0'
this.htmlEl.innerHTML = Notification.generateHtml(text)
Expand Down
6 changes: 4 additions & 2 deletions src/Experience/Utils/Resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ export default class Resources extends EventEmitter {

// loader.innerText = _s.status.fetching

resources.fetchApiThenCache(_api.getBiexChapters(), (json) => {
this.api[_api.getBiexChapters()] = json
const personId = this.experience.auth0.userData ? this.experience.auth0.userData['https://login.bcc.no/claims/personId'] : ''

resources.fetchApiThenCache(_api.getBiexChapters(personId), (json) => {
this.api[_api.getBiexChapters(personId)] = json

console.log('Loading complete!')
this.trigger('ready')
Expand Down
3 changes: 2 additions & 1 deletion src/Experience/World/World.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export default class World {

// Wait for resources
this.resources.on('ready', () => {
instance.chaptersData = instance.resources.api[_api.getBiexChapters()]
const personId = this.experience.auth0.userData ? this.experience.auth0.userData['https://login.bcc.no/claims/personId'] : ''
instance.chaptersData = instance.resources.api[_api.getBiexChapters(personId)]

this.ageCategory = document.getElementById('app-age_category')
this.chapterSelectWrapper = document.getElementById('chapter-select')
Expand Down
62 changes: 26 additions & 36 deletions src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,38 +69,31 @@ const handleRedirectCallback = async () => {
document.body.classList.add('logged-in')

experience.auth0.userData = await experience.auth0.getUser()
let personId = experience.auth0.userData['https://login.bcc.no/claims/personId']
document.dispatchEvent(_e.EVENTS.USER_DATA_FETCHED)
} else {
document.dispatchEvent(_e.EVENTS.USER_DATA_FETCHED)

experience.resources.fetchApiThenCache(_api.getRoles(personId), function (roles) {
// In some cases the function will return an object instead of an array
if (typeof roles === 'object') roles = Object.values(roles)
if (isElectron()) {
document.body.classList.add('not-logged-in')

if (roles.includes('administrator') || roles.includes('editor')) {
document.body.classList.add('admin')
}
})
} else if (isElectron()) {
document.body.classList.add('not-logged-in')

const loginScreen = document.querySelector('#login-screen')
const loginScreen = document.querySelector('#login-screen')

loginScreen.querySelector('.info').textContent = _s.loginScreen.redirectInfo
loginScreen.querySelector('span').textContent = _s.loginScreen.manualRedirectInfo
loginScreen.querySelector('a').textContent = _s.loginScreen.redirectLink
loginScreen.querySelector('.info').textContent = _s.loginScreen.redirectInfo
loginScreen.querySelector('span').textContent = _s.loginScreen.manualRedirectInfo
loginScreen.querySelector('a').textContent = _s.loginScreen.redirectLink

loginScreen.querySelector('a').addEventListener('click', async function (e) {
e.preventDefault()
await experience.auth0.loginWithRedirect({
redirect_uri: 'biex://explorers.biblekids.io',
loginScreen.querySelector('a').addEventListener('click', async function (e) {
e.preventDefault()
await experience.auth0.loginWithRedirect({
redirect_uri: 'biex://explorers.biblekids.io',
})
})
})

setTimeout(() => {
document.querySelector('#login-screen a').click()
}, 2000)
setTimeout(() => {
document.querySelector('#login-screen a').click()
}, 2000)
}
}

document.dispatchEvent(_e.EVENTS.USER_DATA_FETCHED)
}

window.onload = async () => {
Expand Down Expand Up @@ -137,18 +130,16 @@ var browserName = (function (agent) {

if (browserName !== 'Chrome') {
new Notification(_s.browserNotification)
// document.body.appendChild(_gl.elementFromHtml(`<span style="background: red; color: white; position: absolute; top: 7rem; left: 1rem; padding: 0.5rem; border-radius: 1rem; z-index: 99">You are using: ${browserName}</span>`));
}

// adjust screens wrapper size
const dynamicDiv = document.getElementById('screens-wrapper')
const closedCaption = document.getElementById('closed-caption')
const aspectRatio = 1.5
experience.maxVW = 36
const maxVH = 65
const minPaddingTopVh = 6

experience.adjustScreensWrapperSize = () => {
const dynamicDiv = document.getElementById('screens-wrapper')
const closedCaption = document.getElementById('closed-caption')
const aspectRatio = 1.5
experience.maxVW = 36
const maxVH = 65
const minPaddingTopVh = 6

let vw = window.innerWidth * (experience.maxVW / 100)
let vh = window.innerHeight * (maxVH / 100)

Expand All @@ -169,7 +160,6 @@ experience.adjustScreensWrapperSize = () => {

dynamicDiv.style.paddingTop = `${paddingTop}px`
}
experience.adjustScreensWrapperSize()

window.addEventListener('resize', experience.adjustScreensWrapperSize)

experience.adjustScreensWrapperSize()
4 changes: 0 additions & 4 deletions src/scss/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -730,10 +730,6 @@ body.not-logged-in {
display: none;
}
}

.group\/body:not(.admin) &.beta {
display: none;
}
}

.coming-soon {
Expand Down

0 comments on commit 449cbcc

Please sign in to comment.