Fix incorrect edit comment countdown timer calculation #74

This commit is contained in:
Jack
2018-07-25 17:41:13 +04:00
committed by Aleksei Gurianov
parent a817a22471
commit 5c9d0d6119
2 changed files with 11 additions and 2 deletions
+9 -1
View File
@@ -2,6 +2,7 @@ import axios from 'axios';
import { BASE_URL, API_BASE } from './constants';
import { siteId } from './settings';
import store from './store';
const fetcher = {};
const methods = ['get', 'post', 'put', 'patch', 'delete', 'head'];
@@ -35,7 +36,14 @@ methods.forEach(method => {
}
axios(parameters)
.then(res => resolve(res.data))
.then(res => {
const date = ('date' in res.headers && res.headers.date) || '';
const timestamp = isNaN(Date.parse(date)) ? 0 : Date.parse(date);
const timeDiff = (new Date() - timestamp) / 1000;
store.set('serverClientTimeDiff', timeDiff);
resolve(res.data);
})
.catch(error => reject(error));
});
};
+2 -1
View File
@@ -83,7 +83,8 @@ export default class Comment extends Component {
if (userId === commentUserId) {
const editDuration = store.get('config') && store.get('config').edit_duration;
const getEditTimeLeft = () => Math.floor(editDuration - (new Date() - new Date(data.time)) / 1000);
const timeDiff = store.get('serverClientTimeDiff') || 0;
const getEditTimeLeft = () => Math.floor(editDuration - ((new Date() - new Date(data.time)) / 1000 - timeDiff));
if (getEditTimeLeft() > 0) {
this.editTimerInterval = setInterval(() => {