Merge branch 'main' into fix/1797-claim-within-capacity
Quality / check (pull_request) Successful in 7m24s
Quality / check (pull_request) Successful in 7m24s
This commit is contained in:
commit
d70596f4bf
1 file changed
+36
-12
+36
-12
@@ -17,7 +17,7 @@ export function revealBehavior(): ScrollBehavior {
|
||||
</script>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onMounted, ref, watch } from "vue";
|
||||
import { computed, nextTick, onMounted, ref, shallowRef, watch } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
@@ -43,7 +43,9 @@ const router = useRouter();
|
||||
|
||||
// null means loading: an empty list and a list that has not arrived are
|
||||
// different states, and only one of them is worth a spinner.
|
||||
const tasks = ref<Task[] | null>(null);
|
||||
// Rows are replaced, never mutated, so the list is a shallowRef and a reload
|
||||
// that changed nothing triggers nothing.
|
||||
const tasks = shallowRef<Task[] | null>(null);
|
||||
const next = ref<string | null>(null);
|
||||
const loadingMore = ref(false);
|
||||
// A failed page load keeps the rows already shown; only a first-load failure
|
||||
@@ -70,15 +72,12 @@ const requestedTaskId = computed(() => {
|
||||
const status = computed(() => boardStatus(statusQuery.value, statusList()));
|
||||
|
||||
// The server filters by status; search narrows the rows already loaded.
|
||||
const visible = computed(() =>
|
||||
(tasks.value ?? []).filter((task) => {
|
||||
const needle = search.value.trim().toLowerCase();
|
||||
if (!needle) return true;
|
||||
return `${task.title ?? ""} ${task.repo ?? ""}`
|
||||
.toLowerCase()
|
||||
.includes(needle);
|
||||
}),
|
||||
);
|
||||
const visible = computed(() => {
|
||||
const rows = tasks.value ?? [];
|
||||
const needle = search.value.trim().toLowerCase();
|
||||
if (!needle) return rows;
|
||||
return rows.filter((task) => `${task.title ?? ""} ${task.repo ?? ""}`.toLowerCase().includes(needle));
|
||||
});
|
||||
|
||||
// The repo column only earns its width when the rows differ. On a
|
||||
// single-repository deployment it repeated one value down every row while the
|
||||
@@ -103,6 +102,31 @@ const state = computed<"loading" | "error" | "empty" | "no-match">(() => {
|
||||
|
||||
const PAGE = 100;
|
||||
|
||||
// Each live event re-reads the board, and most rows come back unchanged. A row
|
||||
// that is unchanged keeps its object, so the table skips it; a reload that
|
||||
// changed nothing keeps the whole array, so nothing re-renders.
|
||||
const rowJSON = new WeakMap<Task, string>();
|
||||
function serialized(task: Task): string {
|
||||
let json = rowJSON.get(task);
|
||||
if (json === undefined) {
|
||||
json = JSON.stringify(task);
|
||||
rowJSON.set(task, json);
|
||||
}
|
||||
return json;
|
||||
}
|
||||
function mergeRows(previous: Task[] | null, incoming: Task[]): Task[] {
|
||||
if (!previous) return incoming;
|
||||
const byId = new Map(previous.map((task) => [task.id, task]));
|
||||
let changed = previous.length !== incoming.length;
|
||||
const merged = incoming.map((task, index) => {
|
||||
const old = byId.get(task.id);
|
||||
const kept = old && serialized(old) === serialized(task) ? old : task;
|
||||
if (kept !== previous[index]) changed = true;
|
||||
return kept;
|
||||
});
|
||||
return changed ? merged : previous;
|
||||
}
|
||||
|
||||
// Every read bumps the generation; a response that settles after a newer read
|
||||
// started is dropped, so the previous filter's rows or next cursor never land
|
||||
// under the current filter.
|
||||
@@ -117,7 +141,7 @@ async function load() {
|
||||
try {
|
||||
const page = await api.taskPage<Task>({ status: status.value || undefined, limit });
|
||||
if (current !== loadGeneration) return;
|
||||
tasks.value = page.tasks;
|
||||
tasks.value = mergeRows(tasks.value, page.tasks);
|
||||
next.value = page.next;
|
||||
moreError.value = null;
|
||||
} catch (err) {
|
||||
|
||||
Reference in new issue
Block a user