dynamically update post counts
This commit is contained in:
parent
d8d31d9b0a
commit
8236c4526d
|
@ -41,14 +41,14 @@
|
|||
clearTimeout(status_timeout);
|
||||
status_timeout = setTimeout(show_saving, 70);
|
||||
|
||||
send_settings(get_all_inputs())
|
||||
promise = send_settings(get_all_inputs())
|
||||
.then(data => {
|
||||
show_success();
|
||||
clearTimeout(status_timeout);
|
||||
status_timeout = setTimeout(hide_status, 3000);
|
||||
backoff_level = 0;
|
||||
})
|
||||
.catch(e => {
|
||||
});
|
||||
promise.catch(e => {
|
||||
console.error('Fetch rejected:', e);
|
||||
show_error();
|
||||
clearTimeout(status_timeout);
|
||||
|
@ -56,6 +56,7 @@
|
|||
backoff_level += 1;
|
||||
backoff_level = Math.min(backoff_level, 5);
|
||||
});
|
||||
promise.then(fetch_counters).then(update_counters);
|
||||
|
||||
// remove server-rendered banner
|
||||
let settings_section = document.querySelector('#settings-section');
|
||||
|
@ -108,4 +109,19 @@
|
|||
|
||||
// silently send_settings in case the user changed settings while the page was loading
|
||||
send_settings(get_all_inputs());
|
||||
|
||||
function fetch_counters(){
|
||||
return fetch('/api/viewer', {
|
||||
credentials: 'same-origin',
|
||||
})
|
||||
.then(resp => { if(!resp.ok){ return Promise.reject(resp) }; return resp; })
|
||||
.then(resp => resp.json());
|
||||
}
|
||||
|
||||
function update_counters(counters){
|
||||
document.querySelector('#post-count').textContent = counters.post_count;
|
||||
document.querySelector('#eligible-estimate').textContent = counters.eligible_for_delete_estimate;
|
||||
}
|
||||
|
||||
setInterval(() => fetch_counters().then(update_counters), 1000 * 20)
|
||||
})();
|
||||
|
|
10
routes.py
10
routes.py
|
@ -180,3 +180,13 @@ def api_settings_put():
|
|||
updated[key] = data[key]
|
||||
db.session.commit()
|
||||
return jsonify(status='success', updated=updated)
|
||||
|
||||
@app.route('/api/viewer')
|
||||
@require_auth_api
|
||||
def api_viewer_post_counts():
|
||||
viewer = get_viewer()
|
||||
return jsonify(
|
||||
post_count=viewer.post_count(),
|
||||
eligible_for_delete_estimate=viewer.estimate_eligible_for_delete(),
|
||||
# more? maybe later
|
||||
)
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
{% set post_count = g.viewer.account.post_count() %}
|
||||
<p>Currently keeping track of {{ post_count }} of your posts, roughly {{ g.viewer.account.estimate_eligible_for_delete() }} of which currently match your expiration rules.</p>
|
||||
<p>Currently keeping track of <span id="post-count">{{ post_count }}</span> of your posts, roughly <span id="eligible-estimate">{{ g.viewer.account.estimate_eligible_for_delete() }}</span> of which currently match your expiration rules.</p>
|
||||
{% if g.viewer.account.service == 'twitter'
|
||||
and g.viewer.account.reported_post_count
|
||||
and post_count < g.viewer.account.reported_post_count * 3/4
|
||||
|
|
Loading…
Reference in New Issue