Skip to content

Commit

Permalink
no server side errors visible
Browse files Browse the repository at this point in the history
  • Loading branch information
niccolopaganini authored Nov 5, 2023
1 parent 631c1ce commit ad80b56
Showing 1 changed file with 5 additions and 149 deletions.
154 changes: 5 additions & 149 deletions www/js/control/ProfileSettings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,135 +36,6 @@ import { logDebug } from '../plugin/logger';

//any pure functions can go outside
const ProfileSettings = () => {
// anything that mutates must go in --- depend on props or state...
const { t } = useTranslation();
const appConfig = useAppConfig();
const { colors } = useTheme();
const { setPermissionsPopupVis } = useContext(AppContext);

//angular services needed
const CarbonDatasetHelper = getAngularService('CarbonDatasetHelper');
const UploadHelper = getAngularService('UploadHelper');
const EmailHelper = getAngularService('EmailHelper');
const NotificationScheduler = getAngularService('NotificationScheduler');
const ControlHelper = getAngularService('ControlHelper');

//functions that come directly from an Angular service
const editCollectionConfig = () => setEditCollectionVis(true);
const editSyncConfig = () => setEditSync(true);

//states and variables used to control/create the settings
const [opCodeVis, setOpCodeVis] = useState(false);
const [nukeSetVis, setNukeVis] = useState(false);
const [carbonDataVis, setCarbonDataVis] = useState(false);
const [forceStateVis, setForceStateVis] = useState(false);
const [logoutVis, setLogoutVis] = useState(false);
const [invalidateSuccessVis, setInvalidateSuccessVis] = useState(false);
const [noConsentVis, setNoConsentVis] = useState(false);
const [noConsentMessageVis, setNoConsentMessageVis] = useState(false);
const [consentVis, setConsentVis] = useState(false);
const [dateDumpVis, setDateDumpVis] = useState(false);
const [privacyVis, setPrivacyVis] = useState(false);
const [emailVis, setEmailVis] = useState(false);
const [uploadVis, setUploadVis] = useState(false);
const [showingSensed, setShowingSensed] = useState(false);
const [showingLog, setShowingLog] = useState(false);
const [editSync, setEditSync] = useState(false);
const [editCollectionVis, setEditCollectionVis] = useState(false);
// const [collectConfig, setCollectConfig] = useState({});
const [collectSettings, setCollectSettings] = useState({});
const [notificationSettings, setNotificationSettings] = useState({});
const [authSettings, setAuthSettings] = useState({});
const [syncSettings, setSyncSettings] = useState({});
const [cacheResult, setCacheResult] = useState("");
const [connectSettings, setConnectSettings] = useState({});
const [uiConfig, setUiConfig] = useState({});
const [consentDoc, setConsentDoc] = useState({});
const [dumpDate, setDumpDate] = useState(new Date());
const [emailReason, setEmailReason] = useState("");
const [uploadReason, setUploadReason] = useState("");
const appVersion = useRef();

let carbonDatasetString = t('general-settings.carbon-dataset') + ": " + CarbonDatasetHelper.getCurrentCarbonDatasetCode();
const carbonOptions = CarbonDatasetHelper.getCarbonDatasetOptions();
const stateActions = [{text: "Initialize", transition: "INITIALIZE"},
{text: 'Start trip', transition: "EXITED_GEOFENCE"},
{text: 'End trip', transition: "STOPPED_MOVING"},
{text: 'Visit ended', transition: "VISIT_ENDED"},
{text: 'Visit started', transition: "VISIT_STARTED"},
{text: 'Remote push', transition: "RECEIVED_SILENT_PUSH"}]

useEffect(() => {
//added appConfig.name needed to be defined because appConfig was defined but empty
if (appConfig && (appConfig.name)) {
whenReady(appConfig);
}
}, [appConfig]);

const refreshScreen = function() {
refreshCollectSettings();
refreshNotificationSettings();
getOPCode();
getSyncSettings();
getConnectURL();
getAppVersion().then((version) => {
appVersion.current = version;
});
}

//previously not loaded on regular refresh, this ensures it stays caught up
useEffect(() => {
refreshNotificationSettings();
}, [uiConfig])

const whenReady = function(newAppConfig){
var tempUiConfig = newAppConfig;

// backwards compat hack to fill in the raw_data_use for programs that don't have it
const default_raw_data_use = {
"en": `to monitor the ${tempUiConfig.intro.program_or_study}, send personalized surveys or provide recommendations to participants`,
"es": `para monitorear el ${tempUiConfig.intro.program_or_study}, enviar encuestas personalizadas o proporcionar recomendaciones a los participantes`
}
Object.entries(tempUiConfig.intro.translated_text).forEach(([lang, val]) => {
val.raw_data_use = val.raw_data_use || default_raw_data_use[lang];
});

// Backwards compat hack to fill in the `app_required` based on the
// old-style "program_or_study"
// remove this at the end of 2023 when all programs have been migrated over
if (tempUiConfig.intro.app_required == undefined) {
tempUiConfig.intro.app_required = tempUiConfig?.intro.program_or_study == 'program';
}
tempUiConfig.opcode = tempUiConfig.opcode || {};
if (tempUiConfig.opcode.autogen == undefined) {
tempUiConfig.opcode.autogen = tempUiConfig?.intro.program_or_study == 'study';
}

// setTemplateText(tempUiConfig.intro.translated_text);
// console.log("translated text is??", templateText);
setUiConfig(tempUiConfig);
refreshScreen();
}

async function refreshCollectSettings() {
console.debug('about to refreshCollectSettings, collectSettings = ', collectSettings);
const newCollectSettings = {};

// // refresh collect plugin configuration
const collectionPluginConfig = await getHelperCollectionSettings();
newCollectSettings.config = collectionPluginConfig;

const collectionPluginState = await getState();
newCollectSettings.state = collectionPluginState;
newCollectSettings.trackingOn = collectionPluginState != "local.state.tracking_stopped"
&& collectionPluginState != "STATE_TRACKING_STOPPED";

const isLowAccuracy = await isMediumAccuracy();
if (typeof isLowAccuracy != 'undefined') {
newCollectSettings.lowAccuracy = isLowAccuracy;
}

setCollectSettings(newCollectSettings);
// anything that mutates must go in --- depend on props or state...
const { t } = useTranslation();
const appConfig = useAppConfig();
Expand All @@ -173,7 +44,7 @@ const ProfileSettings = () => {

//angular services needed
const CarbonDatasetHelper = getAngularService('CarbonDatasetHelper');
const EmailHelper = getAngularService('EmailHelper');
// const EmailHelper = getAngularService('EmailHelper');
const NotificationScheduler = getAngularService('NotificationScheduler');
const ControlHelper = getAngularService('ControlHelper');

Expand Down Expand Up @@ -270,21 +141,6 @@ const ProfileSettings = () => {
tempUiConfig.opcode.autogen = tempUiConfig?.intro.program_or_study == 'study';
}

const emailLog = function () {
// Passing true, we want to send logs
sendEmail("loggerDB");
setEmailVis(false);
};

async function updatePrefReminderTime(storeNewVal=true, newTime){
console.log(newTime);
if(storeNewVal){
const m = moment(newTime);
// store in HH:mm
NotificationScheduler.setReminderPrefs({ reminder_time_of_day: m.format('HH:mm') }).then(() => {
refreshNotificationSettings();
});
}
// setTemplateText(tempUiConfig.intro.translated_text);
// console.log("translated text is??", templateText);
setUiConfig(tempUiConfig);
Expand Down Expand Up @@ -398,10 +254,10 @@ const ProfileSettings = () => {
}
};

// const emailLog = function () {
// Passing true, we want to send logs
// EmailHelper.sendEmail('loggerDB');
// };
const emailLog = function () {
// Passing true, we want to send logs
EmailHelper.sendEmail('loggerDB');
};

async function updatePrefReminderTime(storeNewVal = true, newTime) {
console.log(newTime);
Expand Down

0 comments on commit ad80b56

Please sign in to comment.