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

🐛 Fix timeline range issues #1183

Merged
merged 5 commits into from
Oct 9, 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
2 changes: 1 addition & 1 deletion package.cordovabuild.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
"cordova-plugin-app-version": "0.1.14",
"cordova-plugin-customurlscheme": "5.0.2",
"cordova-plugin-device": "2.1.0",
"cordova-plugin-em-datacollection": "git+https://github.com/e-mission/e-mission-data-collection.git#v1.9.2",
"cordova-plugin-em-datacollection": "git+https://github.com/e-mission/e-mission-data-collection.git#v1.9.3",
"cordova-plugin-em-opcodeauth": "git+https://github.com/e-mission/cordova-jwt-auth.git#v1.7.2",
"cordova-plugin-em-server-communication": "git+https://github.com/e-mission/cordova-server-communication.git#v1.2.7",
"cordova-plugin-em-serversync": "git+https://github.com/e-mission/cordova-server-sync.git#v1.3.3",
Expand Down
23 changes: 14 additions & 9 deletions www/js/TimelineContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
import { isoDateRangeToTsRange, isoDateWithOffset } from './datetimeUtil';
import { base_modes } from 'e-mission-common';

const TODAY_DATE = DateTime.now().toISODate();
const getTodayDate = () => DateTime.now().toISODate();
// initial date range is the past week: [TODAY - 6 days, TODAY]
const INITIAL_DATE_RANGE: [string, string] = [isoDateWithOffset(TODAY_DATE, -6), TODAY_DATE];
const getPastWeekDateRange = (): [string, string] => {
const todayDate = getTodayDate();
return [isoDateWithOffset(todayDate, -6), todayDate];
};

type ContextProps = {
labelOptions: LabelOptions | null;
Expand Down Expand Up @@ -60,7 +63,7 @@
// date range (inclusive) that has been loaded into the UI [YYYY-MM-DD, YYYY-MM-DD]
const [queriedDateRange, setQueriedDateRange] = useState<[string, string] | null>(null);
// date range (inclusive) chosen by datepicker [YYYY-MM-DD, YYYY-MM-DD]
const [dateRange, setDateRange] = useState<[string, string]>(INITIAL_DATE_RANGE);
const [dateRange, setDateRange] = useState<[string, string]>(getPastWeekDateRange);
// map of timeline entries (trips, places, untracked time), ids to objects
const [timelineMap, setTimelineMap] = useState<TimelineMap | null>(null);
const [timelineIsLoading, setTimelineIsLoading] = useState<string | false>('replace');
Expand Down Expand Up @@ -176,15 +179,15 @@

function loadDateRange(range: [string, string]) {
logDebug('Timeline: loadDateRange with newDateRange = ' + range);
if (!pipelineRange) {
logWarn('No pipelineRange yet - early return from loadDateRange');
if (!pipelineRange?.start_ts) {
logWarn('No pipelineRange start_ts yet - early return from loadDateRange');

Check warning on line 183 in www/js/TimelineContext.ts

View check run for this annotation

Codecov / codecov/patch

www/js/TimelineContext.ts#L183

Added line #L183 was not covered by tests
return;
}
const pipelineStartDate = DateTime.fromSeconds(pipelineRange.start_ts).toISODate();
// clamp range to ensure it is within [pipelineStartDate, TODAY_DATE]
const clampedDateRange: [string, string] = [
new Date(range[0]) < new Date(pipelineStartDate) ? pipelineStartDate : range[0],
new Date(range[1]) > new Date(TODAY_DATE) ? TODAY_DATE : range[1],
new Date(range[1]) > new Date(getTodayDate()) ? getTodayDate() : range[1],
];
if (clampedDateRange[0] != dateRange?.[0] || clampedDateRange[1] != dateRange?.[1]) {
logDebug('Timeline: loadDateRange setting new date range = ' + clampedDateRange);
Expand Down Expand Up @@ -220,8 +223,10 @@
}

async function fetchTripsInRange(dateRange: [string, string]) {
if (!pipelineRange?.start_ts || !pipelineRange?.end_ts)
return logWarn('No pipelineRange yet - early return');
if (!pipelineRange?.start_ts || !pipelineRange?.end_ts) {
logDebug('No pipelineRange yet, returning empty lists');
return [[], []];

Check warning on line 228 in www/js/TimelineContext.ts

View check run for this annotation

Codecov / codecov/patch

www/js/TimelineContext.ts#L227-L228

Added lines #L227 - L228 were not covered by tests
}
logDebug('Timeline: fetchTripsInRange from ' + dateRange[0] + ' to ' + dateRange[1]);

const [startTs, endTs] = isoDateRangeToTsRange(dateRange);
Expand Down Expand Up @@ -257,7 +262,7 @@
try {
logDebug('timelineContext: refreshTimeline');
setTimelineIsLoading('replace');
setDateRange(INITIAL_DATE_RANGE);
setDateRange(getPastWeekDateRange());

Check warning on line 265 in www/js/TimelineContext.ts

View check run for this annotation

Codecov / codecov/patch

www/js/TimelineContext.ts#L265

Added line #L265 was not covered by tests
setQueriedDateRange(null);
setTimelineMap(null);
setRefreshTime(new Date());
Expand Down
3 changes: 2 additions & 1 deletion www/js/diary/list/TimelineScrollList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ const TimelineScrollList = ({ listEntries }: Props) => {
</LoadMoreButton>
);

const pipelineEndDate = pipelineRange && DateTime.fromSeconds(pipelineRange.end_ts).toISODate();
const pipelineEndDate =
pipelineRange?.end_ts && DateTime.fromSeconds(pipelineRange.end_ts).toISODate();
const noTravelBanner = (
<Banner visible={true} icon={({ size }) => <Icon source="alert-circle" size={size} />}>
<View style={{ width: '100%' }}>
Expand Down
23 changes: 14 additions & 9 deletions www/js/usePermissionStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import { useAppTheme } from './appTheme';
import { logDebug, logWarn } from './plugin/logger';
import { AlertManager } from './components/AlertBar';
import { storageGet } from './plugin/storage';

const HAS_REQUESTED_NOTIFS_KEY = 'HasRequestedNotificationPermission';

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

View check run for this annotation

Codecov / codecov/patch

www/js/usePermissionStatus.ts#L10

Added line #L10 was not covered by tests

let DEVICE_PLATFORM: 'android' | 'ios';
let DEVICE_VERSION: number;
Expand Down Expand Up @@ -224,7 +227,7 @@
}
}

function setupNotificationChecks() {
function setupNotificationChecks(hasRequestedNotifs) {

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
let fixPerms = () => {
logDebug('fix and refresh notification permissions');
appAndChannelNotificationsCheck.wasRequested = true;
Expand Down Expand Up @@ -252,7 +255,7 @@
fix: fixPerms,
refresh: checkPerms,
isOptional: true,
wasRequested: false,
wasRequested: hasRequestedNotifs,
};
let tempChecks = checkList;
tempChecks.push(appAndChannelNotificationsCheck);
Expand Down Expand Up @@ -344,7 +347,7 @@
logDebug('Explanation = ' + explanationList);
}

function createChecklist() {
function createChecklist(hasRequestedNotifs) {

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

View check run for this annotation

Codecov / codecov/patch

www/js/usePermissionStatus.ts#L350

Added line #L350 was not covered by tests
setupLocChecks();
setupFitnessChecks();
if (DEVICE_PLATFORM == 'android') {
Expand All @@ -353,7 +356,7 @@
}
setupAndroidBackgroundRestrictionChecks();
}
setupNotificationChecks();
setupNotificationChecks(hasRequestedNotifs);

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

View check run for this annotation

Codecov / codecov/patch

www/js/usePermissionStatus.ts#L359

Added line #L359 was not covered by tests
refreshAllChecks(checkList);
}

Expand All @@ -365,11 +368,13 @@
//load when ready
useEffect(() => {
if (appConfig && window['device']?.platform) {
DEVICE_PLATFORM = window['device'].platform.toLowerCase();
DEVICE_VERSION = window['device'].version.split('.')[0];
setupPermissionText();
logDebug('setting up permissions');
createChecklist();
storageGet(HAS_REQUESTED_NOTIFS_KEY).then((hasRequestedNotifs) => {
DEVICE_PLATFORM = window['device'].platform.toLowerCase();
DEVICE_VERSION = window['device'].version.split('.')[0];
setupPermissionText();
logDebug('setting up permissions');
createChecklist(hasRequestedNotifs);

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

View check run for this annotation

Codecov / codecov/patch

www/js/usePermissionStatus.ts#L371-L376

Added lines #L371 - L376 were not covered by tests
});
}
}, [appConfig]);

Expand Down
Loading