Skip to content

Commit

Permalink
Fix partial loading of now items when filtering the past
Browse files Browse the repository at this point in the history
  • Loading branch information
easteregg committed Jun 27, 2019
1 parent 07f0bcb commit 90272ea
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
19 changes: 15 additions & 4 deletions src/javascript/app/Stores/Modules/Profit/Helpers/format-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import {
} from 'Utils/Date';

const getDateTo = (partial_fetch_time, date_to) => {
if (partial_fetch_time) {
const today = toMoment().startOf('day').unix();
if (date_to && today > date_to) {
return epochToMoment(date_to)
.add(1, 'd')
.subtract(1, 's')
.unix();
} else if (partial_fetch_time) {
return toMoment().endOf('day').unix();
} else if (date_to) {
return epochToMoment(date_to)
Expand All @@ -15,13 +21,18 @@ const getDateTo = (partial_fetch_time, date_to) => {
return toMoment().endOf('day').unix();
};

const getDateFrom = (should_load_partially, partial_fetch_time, date_from) =>
should_load_partially && partial_fetch_time ? partial_fetch_time : date_from;
const getDateFrom = (should_load_partially, partial_fetch_time, date_from, date_to) => {
const today = toMoment().startOf('day').unix();
if (today > date_to) {
return date_from;
}
return should_load_partially && partial_fetch_time ? partial_fetch_time : date_from;
};

const getDateBoundaries = (date_from, date_to, partial_fetch_time, should_load_partially = false) => (
{
// eslint-disable-next-line max-len
...(date_from || should_load_partially) && { date_from: getDateFrom(should_load_partially, partial_fetch_time, date_from) },
...(date_from || should_load_partially) && { date_from: getDateFrom(should_load_partially, partial_fetch_time, date_from, date_to) },
...(date_to || should_load_partially) && { date_to: getDateTo(partial_fetch_time, date_to) },
}
);
Expand Down
9 changes: 8 additions & 1 deletion src/javascript/app/Stores/Modules/Profit/profit-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,16 @@ export default class ProfitTableStore extends BaseStore {
return !!(this.date_from || this.date_to);
}
shouldFetchNextBatch(should_load_partially) {
if (!should_load_partially && (this.has_loaded_all || this.is_loading)) return false;
const today = toMoment().startOf('day');
if (should_load_partially && this.date_to && this.date_to < today) return false;
return true;
}
@action.bound
async fetchNextBatch(should_load_partially = false) {
if (!should_load_partially && (this.has_loaded_all || this.is_loading)) return;
if (!this.shouldFetchNextBatch(should_load_partially)) return;
this.is_loading = true;
const response = await WS.profitTable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,16 @@ export default class StatementStore extends BaseStore {
this.date_to = 0;
}
shouldFetchNextBatch(should_load_partially) {
if (!should_load_partially && (this.has_loaded_all || this.is_loading)) return false;
const today = toMoment().startOf('day');
if (should_load_partially && this.date_to && this.date_to < today) return false;
return true;
}
@action.bound
async fetchNextBatch(should_load_partially = false) {
if (!should_load_partially && (this.has_loaded_all || this.is_loading)) return;
if (!this.shouldFetchNextBatch(should_load_partially)) return;
this.is_loading = true;
const response = await WS.statement(
Expand Down

0 comments on commit 90272ea

Please sign in to comment.