Skip to content

Commit

Permalink
add "wasRequested" for optional notif permission; update UI
Browse files Browse the repository at this point in the history
Although the notifs perm is optional, we do want to make sure the user is at least prompted for it. We need to ensure that overallStatus stays false until notif perms have been requested. We keep track of 'wasRequested', overallStatus will only pass if all checks are status=true or they are optional and have already been requested (ie they were explictly denied)

We can also have this reflected in the UI; use 'outline' icons to indicate a check that was not yet prompted and use 'filled in' icons to indicate an explicit choice.
Moved this to a separate function iconAndColorForCheck for tidiness
  • Loading branch information
JGreenlee committed Oct 5, 2024
1 parent 1121676 commit 112e9de
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
23 changes: 10 additions & 13 deletions www/js/appstatus/PermissionItem.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
import React from 'react';
import { List, Button } from 'react-native-paper';
import { List } from 'react-native-paper';
import { useTranslation } from 'react-i18next';
import { useAppTheme } from '../appTheme';
import { colors } from '../appTheme';

function iconAndColorForCheck(check) {

Check warning on line 6 in www/js/appstatus/PermissionItem.tsx

View check run for this annotation

Codecov / codecov/patch

www/js/appstatus/PermissionItem.tsx#L6

Added line #L6 was not covered by tests
if (check.status) return ['check-circle', colors.success];
if (!check.isOptional) return ['alert-circle', colors.error];
return [check.wasRequested ? 'minus-circle-off' : 'minus-circle-off-outline', colors.warn];
}

const PermissionItem = ({ check }) => {
const { t } = useTranslation();
const { colors } = useAppTheme();

let icon, color;
if (check.status) {
icon = 'check-circle';
color = colors.success;
} else {
icon = check.isOptional ? 'minus-circle-off' : 'alert-circle-outline';
color = check.isOptional ? colors.warn : colors.error;
}
const [icon, color] = iconAndColorForCheck(check);

Check warning on line 14 in www/js/appstatus/PermissionItem.tsx

View check run for this annotation

Codecov / codecov/patch

www/js/appstatus/PermissionItem.tsx#L14

Added line #L14 was not covered by tests

return (
<List.Item
onPress={() => check.fix()}

Check warning on line 18 in www/js/appstatus/PermissionItem.tsx

View check run for this annotation

Codecov / codecov/patch

www/js/appstatus/PermissionItem.tsx#L18

Added line #L18 was not covered by tests
title={t(check.name)}
description={t(check.desc)}
description={!check.status ? t(check.desc) : null}
descriptionNumberOfLines={5}
left={() => <List.Icon icon={icon} color={color} />}
right={() => <List.Icon icon="chevron-right" />}

Check warning on line 23 in www/js/appstatus/PermissionItem.tsx

View check run for this annotation

Codecov / codecov/patch

www/js/appstatus/PermissionItem.tsx#L22-L23

Added lines #L22 - L23 were not covered by tests
Expand Down
11 changes: 9 additions & 2 deletions www/js/usePermissionStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Check = {
refresh: () => Promise<any>;
status?: boolean;
isOptional?: boolean;
wasRequested?: boolean;
};

const usePermissionStatus = () => {
Expand All @@ -36,7 +37,7 @@ const usePermissionStatus = () => {

const overallStatus = useMemo<boolean | undefined>(() => {
if (!checkList?.length) return undefined; // if checks not loaded yet, status is undetermined
return checkList.every((check) => check.status || check.isOptional);
return checkList.every((check) => check.status || (check.isOptional && check.wasRequested));
}, [checkList]);

//using this function to update checks rather than mutate
Expand Down Expand Up @@ -226,11 +227,16 @@ const usePermissionStatus = () => {
function setupNotificationChecks() {

Check warning on line 227 in www/js/usePermissionStatus.ts

View check run for this annotation

Codecov / codecov/patch

www/js/usePermissionStatus.ts#L227

Added line #L227 was not covered by tests
let fixPerms = () => {
logDebug('fix and refresh notification permissions');
appAndChannelNotificationsCheck.wasRequested = true;

Check warning on line 230 in www/js/usePermissionStatus.ts

View check run for this annotation

Codecov / codecov/patch

www/js/usePermissionStatus.ts#L230

Added line #L230 was not covered by tests
return checkOrFix(
appAndChannelNotificationsCheck,
window['cordova'].plugins.BEMDataCollection.fixShowNotifications,
true,
);
).then((error) => {

Check warning on line 235 in www/js/usePermissionStatus.ts

View check run for this annotation

Codecov / codecov/patch

www/js/usePermissionStatus.ts#L235

Added line #L235 was not covered by tests
if (error) {
appAndChannelNotificationsCheck.desc = error;

Check warning on line 237 in www/js/usePermissionStatus.ts

View check run for this annotation

Codecov / codecov/patch

www/js/usePermissionStatus.ts#L237

Added line #L237 was not covered by tests
}
});
};
let checkPerms = () => {
logDebug('refresh notification permissions');

Check warning on line 242 in www/js/usePermissionStatus.ts

View check run for this annotation

Codecov / codecov/patch

www/js/usePermissionStatus.ts#L242

Added line #L242 was not covered by tests
Expand All @@ -246,6 +252,7 @@ const usePermissionStatus = () => {
fix: fixPerms,
refresh: checkPerms,
isOptional: true,
wasRequested: false,
};
let tempChecks = checkList;
tempChecks.push(appAndChannelNotificationsCheck);
Expand Down

0 comments on commit 112e9de

Please sign in to comment.