mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-10 23:01:10 +00:00
Improve relay hygiene and count status
This commit is contained in:
1 parent
6ae4b7ab4f
commit
c3e986c9d3
12 files changed
+286
-59
No files matched your search
@@ -6201,11 +6201,16 @@ export class VideoModal {
|
||||
try {
|
||||
const token = subscribeToVideoViewCount(
|
||||
pointerInfo.pointer,
|
||||
({ total, status }) => {
|
||||
({ total, status, partial }) => {
|
||||
if (!viewEl || !viewEl.isConnected) {
|
||||
return;
|
||||
}
|
||||
viewEl.textContent = this.getViewCountLabel(total, status);
|
||||
viewEl.textContent = this.getViewCountLabel(total, status, partial);
|
||||
if (partial) {
|
||||
viewEl.dataset.viewCountState = "partial";
|
||||
} else {
|
||||
viewEl.dataset.viewCountState = status;
|
||||
}
|
||||
}
|
||||
);
|
||||
return { pointer: pointerInfo.pointer, token };
|
||||
@@ -6216,9 +6221,10 @@ export class VideoModal {
|
||||
}
|
||||
}
|
||||
|
||||
getViewCountLabel(total, status) {
|
||||
getViewCountLabel(total, status, partial) {
|
||||
if (Number.isFinite(total)) {
|
||||
return this.formatViewCountLabel(Number(total));
|
||||
const label = this.formatViewCountLabel(Number(total));
|
||||
return partial ? `${label} (partial)` : label;
|
||||
}
|
||||
if (status === "hydrating") {
|
||||
return "Loading…";
|
||||
|
||||
@@ -1134,16 +1134,20 @@ export class VideoListView {
|
||||
elements: new Set(),
|
||||
lastTotal: null,
|
||||
lastStatus: "idle",
|
||||
lastPartial: false,
|
||||
lastText: "– views",
|
||||
};
|
||||
|
||||
try {
|
||||
const token = subscribeToVideoViewCount(pointerInfo.pointer, ({ total, status }) => {
|
||||
const token = subscribeToVideoViewCount(pointerInfo.pointer, ({ total, status, partial }) => {
|
||||
let text;
|
||||
if (Number.isFinite(total)) {
|
||||
const numeric = Number(total);
|
||||
entry.lastTotal = numeric;
|
||||
text = this.formatters.formatViewCountLabel(numeric);
|
||||
if (partial) {
|
||||
text = `${text} (partial)`;
|
||||
}
|
||||
} else if (status === "hydrating") {
|
||||
text = "Loading views…";
|
||||
} else {
|
||||
@@ -1151,6 +1155,7 @@ export class VideoListView {
|
||||
}
|
||||
|
||||
entry.lastStatus = status;
|
||||
entry.lastPartial = Boolean(partial);
|
||||
entry.lastText = text;
|
||||
|
||||
for (const el of Array.from(entry.elements)) {
|
||||
@@ -1159,6 +1164,11 @@ export class VideoListView {
|
||||
continue;
|
||||
}
|
||||
el.textContent = text;
|
||||
if (entry.lastPartial) {
|
||||
el.dataset.viewCountState = "partial";
|
||||
} else {
|
||||
el.dataset.viewCountState = status;
|
||||
}
|
||||
}
|
||||
});
|
||||
entry.token = token;
|
||||
@@ -1193,6 +1203,9 @@ export class VideoListView {
|
||||
if (typeof pointerInfo.key === "string") {
|
||||
viewCountEl.dataset.viewPointer = pointerInfo.key;
|
||||
}
|
||||
viewCountEl.dataset.viewCountState = entry.lastPartial
|
||||
? "partial"
|
||||
: entry.lastStatus;
|
||||
viewCountEl.textContent = entry.lastText;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user