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 a506f6c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CompositeCalendar extends React.PureComponent {
this.state = {
show_to : false,
show_from : false,
selected_to_date : props.to ? props.to : date.unix(),
selected_to_date : props.to ? props.to : date.clone().startOf('day').add(1, 'd').subtract(1, 's').unix(),
selected_from_date: props.from ? props.from : null,
list : [
{ children: localize('All time'), onClick: () => this.selectDateRange(0), duration: 0, is_active: true },
Expand All @@ -36,7 +36,7 @@ class CompositeCalendar extends React.PureComponent {

selectDateRange (from) {
this.setState({
selected_from_date: from ? toMoment().startOf('day').subtract(from, 'day').unix() : null,
selected_from_date: from ? toMoment().startOf('day').subtract(from, 'day').add(1, 's').unix() : null,
selected_to_date : toMoment().startOf('day').unix(),
}, () => {
this.setActiveList();
Expand Down Expand Up @@ -113,7 +113,7 @@ class CompositeCalendar extends React.PureComponent {
}

setToDate (date) {
this.updateState('selected_to_date', date);
this.updateState('selected_to_date', epochToMoment(date).startOf('day').add(1, 'd').subtract(1, 's').unix());
}

setFromDate(date) {
Expand Down
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
13 changes: 9 additions & 4 deletions 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').add(1, 'd').subtract(1, 's').unix();
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 Expand Up @@ -159,9 +166,7 @@ export default class ProfitTableStore extends BaseStore {
@action.bound
handleDateChange(date_values) {
Object.keys(date_values).forEach(key => {
if (date_values[key]) {
this[`date_${key}`] = date_values[key];
}
this[`date_${key}`] = date_values[key];
});
this.clearTable();
this.fetchNextBatch();
Expand Down
13 changes: 9 additions & 4 deletions src/javascript/app/Stores/Modules/Statement/statement-store.js
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').add(1, 'd').subtract(1, 's').unix();
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 Expand Up @@ -92,9 +99,7 @@ export default class StatementStore extends BaseStore {
@action.bound
handleDateChange(date_values) {
Object.keys(date_values).forEach(key => {
if (date_values[key]) {
this[`date_${key}`] = date_values[key];
}
this[`date_${key}`] = date_values[key];
});
this.clearTable();
this.fetchNextBatch();
Expand Down

0 comments on commit a506f6c

Please sign in to comment.