Fix incorrect edit comment countdown timer calculation #74
This commit is contained in:
@@ -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));
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
Reference in New Issue
Block a user