Skip to content

Fix nudging for students (100%) #83

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

Merged
merged 8 commits into from
Jun 25, 2024
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
74,875 changes: 74,872 additions & 3 deletions src/build/bundles/app.bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/build/bundles/app.bundle.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/entry/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
inappPaintEditorGuide,
inappPrivacyPolicy,
} from "./inapp";
import setupRealtime from './setupRealtime';

/* This function replicates the behavior of the `.on<event>` properties but is
* implemented using `addEventListener` and `removeEventListener`. This allows
Expand Down Expand Up @@ -205,4 +206,6 @@ window.onload = async () => {
// Initialize currentUsage data
InitialOptions.initWithSettings(window.Settings.initialOptions);
});

setupRealtime();
};
36 changes: 36 additions & 0 deletions src/entry/setupRealtime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* This is used to get nudging/focus to work for students in Scratch JR.
*/

import { getDatabase } from 'firebase/database';
import { initializeApp } from 'firebase/app';
import { ref } from 'firebase/database';
import { onChildChanged } from 'firebase/database';

function getFirebaseRef ( userID ) {
// Returns reference to a node on Realtime Database"
var isLocal = window.isLocal;

var FIREBASE_URL = 'https://live-dashboard-d4d0e-default-rtdb.firebaseio.com/';
var refPath = isLocal ? 'LOCAL_NAV/' : 'LIVE_NAV/';
refPath += userID;
var firebaseApp = initializeApp({

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might need to be careful here - if firebase is already on the window this can cause issues. lets hold off for now and talk about it, maybe we can loop in @john-kelly as well

databaseURL: FIREBASE_URL
});

const db = getDatabase(firebaseApp);
var nodeRef = ref(db, refPath);
return nodeRef;
}

function navigateToUrl (snapshot) {
var url = snapshot.val();
if (url && window.location.pathname != url) {
window.location.href = url;
}
}

export default function setupRealtime () {
var nodeRef = getFirebaseRef(window.userData.id);
onChildChanged(nodeRef, navigateToUrl);
}