feat: correct recent Today updates in place (Closes #1062)
This commit is contained in:
1 parent
9c46455c35
commit
8b4bd480cc
7 files changed
+231
-32
No files matched your search
@@ -1,28 +1,23 @@
|
||||
function createConversationActionHydrator({ load, activate }) {
|
||||
let actions = null;
|
||||
let pending = null;
|
||||
const wiredRoots = new WeakSet();
|
||||
const wired = new WeakSet();
|
||||
|
||||
function ensure() {
|
||||
if (actions) return Promise.resolve(actions);
|
||||
if (!pending) {
|
||||
pending = load().then(() => {
|
||||
actions = activate();
|
||||
return actions;
|
||||
}).catch(error => {
|
||||
pending = null;
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
async function ensure() {
|
||||
if (actions) return actions;
|
||||
if (!pending) pending = load().then(() => actions = activate()).catch(error => {
|
||||
pending = null;
|
||||
throw error;
|
||||
});
|
||||
return pending;
|
||||
}
|
||||
|
||||
function show({ root, state, paint, wire, retry }) {
|
||||
if (actions) {
|
||||
retry.hidden = true;
|
||||
if (!wiredRoots.has(root)) {
|
||||
if (!wired.has(root)) {
|
||||
wire(actions);
|
||||
wiredRoots.add(root);
|
||||
wired.add(root);
|
||||
}
|
||||
paint(state, actions);
|
||||
return Promise.resolve(true);
|
||||
@@ -31,9 +26,9 @@ function createConversationActionHydrator({ load, activate }) {
|
||||
paint(state, null);
|
||||
retry.hidden = true;
|
||||
return ensure().then(controller => {
|
||||
if (!wiredRoots.has(root)) {
|
||||
if (!wired.has(root)) {
|
||||
wire(controller);
|
||||
wiredRoots.add(root);
|
||||
wired.add(root);
|
||||
}
|
||||
paint(state, controller);
|
||||
return true;
|
||||
@@ -43,7 +38,7 @@ function createConversationActionHydrator({ load, activate }) {
|
||||
});
|
||||
}
|
||||
|
||||
return { show, ready: () => Boolean(actions) };
|
||||
return {show,get:ensure};
|
||||
}
|
||||
|
||||
if (typeof module !== 'undefined' && module.exports) module.exports = createConversationActionHydrator;
|
||||
@@ -990,7 +990,7 @@
|
||||
issueOutbox.reconcileBackground(records);
|
||||
authoredOutbox.reconcileBackground(records);
|
||||
notificationReadOutbox.reconcileBackground(records);
|
||||
}).catch(() => { /* The foreground localStorage outboxes remain available. */ });
|
||||
}).catch(() => {});
|
||||
}
|
||||
const shareParams = new URLSearchParams(location.search);
|
||||
const appShortcut = mobileAppShortcuts.createController({
|
||||
@@ -1012,7 +1012,7 @@
|
||||
'comment-actions': document.querySelector('meta[name="stackchain-feature-comment-actions"]')?.content || '',
|
||||
},
|
||||
});
|
||||
const commentActionHydrator = createConversationActionHydrator({
|
||||
const actionHydrator = createConversationActionHydrator({
|
||||
load: () => commentActionFeatures.load('comment-actions'),
|
||||
activate: () => {
|
||||
commentActions = createCommentActions({
|
||||
@@ -1968,7 +1968,7 @@
|
||||
const todayProgressView = createTodayProgressView({
|
||||
progress:todayProgress, currentTarget:currentTodayProgressTarget, qs, photos:todayProgressPhotos,
|
||||
voice:todayProgressVoice,
|
||||
activity:mountTodayProgressActivity(qs, fetchReviewJson),
|
||||
activity:mountTodayProgressActivity(qs,fetchReviewJson,actionHydrator,renderMarkdown),
|
||||
announce:message => { qs('#my-work-action-status').textContent = message; },
|
||||
onAdmitted:() => refreshMyWorkView(),
|
||||
});
|
||||
@@ -3871,7 +3871,7 @@
|
||||
function showConversationWithActions(kind, state) {
|
||||
const surface = conversationActionSurfaces[kind];
|
||||
latestConversationStates[kind] = state;
|
||||
return commentActionHydrator.show({
|
||||
return actionHydrator.show({
|
||||
root:qs(surface.selector), state, paint:surface.paint,
|
||||
retry:qs('#retry-' + kind + '-comment-actions'),
|
||||
wire:controller => wireConversationActions(kind, controller),
|
||||
|
||||
@@ -132,10 +132,11 @@ maxLength = 2000, maxItems = 20 }) {
|
||||
return { load, save, discard:identity => save(identity, ''), post };
|
||||
}
|
||||
|
||||
function createTodayProgressActivity({ fetchJson, createPager, paint = () => {}, setStatus = () => {} }) {
|
||||
function createTodayProgressActivity({ fetchJson, createPager, getActions, onActions, surfaceStatus, paint = () => {}, setStatus = () => {} }) {
|
||||
let requestToken = 0;
|
||||
let pager = null;
|
||||
let target = null;
|
||||
let actions = null;
|
||||
|
||||
const pathFor = (value, page) => {
|
||||
const repository = String(value.repository || '').split('/').map(encodeURIComponent).join('/');
|
||||
@@ -153,6 +154,9 @@ function createTodayProgressActivity({ fetchJson, createPager, paint = () => {},
|
||||
const page = await loadPage();
|
||||
if (token !== requestToken || target.identity !== value.identity) return false;
|
||||
pager = createPager({ loadPage });
|
||||
actions = typeof getActions === 'function' ? await getActions() : null;
|
||||
if (token !== requestToken || target.identity !== value.identity) return false;
|
||||
onActions?.(actions);
|
||||
paint(pager.reset(page));
|
||||
setStatus('');
|
||||
return true;
|
||||
@@ -182,29 +186,51 @@ function createTodayProgressActivity({ fetchJson, createPager, paint = () => {},
|
||||
open,
|
||||
retry:() => target ? open(target) : Promise.resolve(false),
|
||||
loadOlder,
|
||||
close:() => { requestToken++; target = null; pager = null; setStatus(''); },
|
||||
actionHtml:comment => actions?.actionHtml?.(comment) || '',
|
||||
surface:() => ({
|
||||
context:{ kind:target?.kind, item:target }, pager,
|
||||
status:surfaceStatus, render:paint,
|
||||
}),
|
||||
close:() => { requestToken++; target = null; pager = null; actions = null; setStatus(''); },
|
||||
};
|
||||
}
|
||||
|
||||
function mountTodayProgressActivity(qs, fetchJson) {
|
||||
function mountTodayProgressActivity(qs, fetchJson, actionSource = {}, render) {
|
||||
const options = actionSource.get && !actionSource.getActions ?
|
||||
{ getActions:actionSource.get, isOffline:() => !navigator.onLine } : actionSource;
|
||||
const escape = options.escape || (value => String(value).replace(/[&<>"']/g,
|
||||
character => ({'&':'&','<':'<','>':'>','"':'"',"'":'''})[character]));
|
||||
render ||= options.render;
|
||||
const list = qs('#today-progress-activity-list');
|
||||
const optionsStatus = qs('#today-progress-activity-status');
|
||||
let actionsWired = false;
|
||||
const activity = createTodayProgressActivity({
|
||||
fetchJson,
|
||||
createPager:createConversationPager,
|
||||
createPager:options.createPager || createConversationPager,
|
||||
getActions:options.getActions,
|
||||
surfaceStatus:optionsStatus,
|
||||
onActions:actions => {
|
||||
if (actionsWired || !actions?.wire) return;
|
||||
actions.wire({ root:list, getSurface:() => activity.surface(),
|
||||
isOffline:options.isOffline || (() => false), escapeHtml:escape });
|
||||
actionsWired = true;
|
||||
},
|
||||
paint:state => {
|
||||
const list = qs('#today-progress-activity-list');
|
||||
list.innerHTML = (state.comments || []).map(comment => {
|
||||
const author = comment.author || comment.user?.login || 'Unknown author';
|
||||
const timing = comment.created_at ? ' · ' + new Date(comment.created_at).toLocaleString() : '';
|
||||
return '<article class="today-progress-activity-item"><div class="small muted">' +
|
||||
escapeHtml(author) + escapeHtml(timing) + '</div><div class="markdown-content">' +
|
||||
renderMarkdown(comment.body || 'No message body provided.') + '</div></article>';
|
||||
return '<article class="today-progress-activity-item issue-comment" data-comment-id="' +
|
||||
escape(String(comment.id)) + '"><div class="small muted">' +
|
||||
escape(author) + escape(timing) + '</div><div class="markdown-content">' +
|
||||
render(comment.body || 'No message body provided.') + '</div>' +
|
||||
activity.actionHtml(comment) + '</article>';
|
||||
}).join('');
|
||||
qs('#today-progress-activity-count').textContent = state.total ?
|
||||
String(state.comments.length) + ' of ' + String(state.total) + ' messages' : '';
|
||||
qs('#load-older-today-progress-activity').hidden = !Number.isInteger(state.older_page);
|
||||
},
|
||||
setStatus:message => {
|
||||
qs('#today-progress-activity-status').textContent = message;
|
||||
optionsStatus.textContent = message;
|
||||
qs('#retry-today-progress-activity').hidden = !message.includes('unavailable');
|
||||
},
|
||||
});
|
||||
@@ -368,4 +394,5 @@ if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports.createView = createTodayProgressView;
|
||||
module.exports.createPhotos = createTodayProgressPhotos;
|
||||
module.exports.createActivity = createTodayProgressActivity;
|
||||
module.exports.mountActivity = mountTodayProgressActivity;
|
||||
}
|
||||
Reference in new issue
Block a user