Intermediate commit
This commit is contained in:
parent
0e9e49df16
commit
3d4cfeff1a
65 changed files with 5507 additions and 333 deletions
|
|
@ -1,5 +1,5 @@
|
|||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from "vue";
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from "vue";
|
||||
|
||||
import { fetchDashboardSnapshot, type DashboardSnapshot } from "@/features/dashboard";
|
||||
import { ApiRequestError } from "@/lib/api/errors";
|
||||
|
|
@ -26,6 +26,8 @@ const refreshingAfterCompletion = ref(false);
|
|||
const auth = useAuthStore();
|
||||
const runStatus = useRunStatusStore();
|
||||
const userSettings = useUserSettingsStore();
|
||||
const DASHBOARD_RUN_STATUS_SYNC_INTERVAL_MS = 5000;
|
||||
let runStatusSyncTimer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
const isStartBlocked = computed(
|
||||
() =>
|
||||
|
|
@ -145,13 +147,35 @@ function shouldRefreshAfterRunChange(
|
|||
if (!nextRun || !previousRun) {
|
||||
return false;
|
||||
}
|
||||
if (nextRun.status === "running") {
|
||||
return false;
|
||||
}
|
||||
if (nextRun.id !== previousRun.id) {
|
||||
return true;
|
||||
}
|
||||
return previousRun.status === "running";
|
||||
if (nextRun.status === previousRun.status) {
|
||||
return false;
|
||||
}
|
||||
const nextActive = nextRun.status === "running" || nextRun.status === "resolving";
|
||||
const previousActive = previousRun.status === "running" || previousRun.status === "resolving";
|
||||
return nextActive || previousActive;
|
||||
}
|
||||
|
||||
function startRunStatusSyncLoop(): void {
|
||||
if (runStatusSyncTimer !== null) {
|
||||
return;
|
||||
}
|
||||
runStatusSyncTimer = setInterval(() => {
|
||||
if (runStatus.isRunActive) {
|
||||
return;
|
||||
}
|
||||
void runStatus.syncLatest();
|
||||
}, DASHBOARD_RUN_STATUS_SYNC_INTERVAL_MS);
|
||||
}
|
||||
|
||||
function stopRunStatusSyncLoop(): void {
|
||||
if (runStatusSyncTimer === null) {
|
||||
return;
|
||||
}
|
||||
clearInterval(runStatusSyncTimer);
|
||||
runStatusSyncTimer = null;
|
||||
}
|
||||
|
||||
async function loadSnapshot(): Promise<void> {
|
||||
|
|
@ -228,10 +252,15 @@ async function onCancelRun(): Promise<void> {
|
|||
}
|
||||
|
||||
onMounted(() => {
|
||||
startRunStatusSyncLoop();
|
||||
void loadSnapshot();
|
||||
void runStatus.syncLatest();
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
stopRunStatusSyncLoop();
|
||||
});
|
||||
|
||||
watch(
|
||||
() => runStatus.latestRun,
|
||||
(nextRun, previousRun) => {
|
||||
|
|
@ -372,7 +401,7 @@ watch(
|
|||
<AppButton
|
||||
v-if="auth.isAdmin && runStatus.isLikelyRunning"
|
||||
variant="danger"
|
||||
:disabled="!activeRunId || isCancelAnimating.value"
|
||||
:disabled="!activeRunId || isCancelAnimating"
|
||||
@click="onCancelRun"
|
||||
>
|
||||
<span class="inline-flex items-center gap-2">
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from "vue";
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
|
||||
import AppPage from "@/components/layout/AppPage.vue";
|
||||
|
|
@ -33,7 +33,8 @@ type PublicationSortKey =
|
|||
| "scholar"
|
||||
| "year"
|
||||
| "citations"
|
||||
| "first_seen";
|
||||
| "first_seen"
|
||||
| "pdf_status";
|
||||
|
||||
type BulkAction =
|
||||
| "mark_selected_read"
|
||||
|
|
@ -70,6 +71,8 @@ const router = useRouter();
|
|||
const textCollator = new Intl.Collator(undefined, { sensitivity: "base", numeric: true });
|
||||
const runStatus = useRunStatusStore();
|
||||
const userSettings = useUserSettingsStore();
|
||||
const PUBLICATIONS_RUN_STATUS_SYNC_INTERVAL_MS = 5000;
|
||||
let runStatusSyncTimer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
function normalizeScholarFilterQuery(value: unknown): string {
|
||||
if (Array.isArray(value)) {
|
||||
|
|
@ -179,6 +182,26 @@ function publicationIdentifierLabel(item: PublicationItem): string | null {
|
|||
return item.display_identifier?.label ?? null;
|
||||
}
|
||||
|
||||
function startRunStatusSyncLoop(): void {
|
||||
if (runStatusSyncTimer !== null) {
|
||||
return;
|
||||
}
|
||||
runStatusSyncTimer = setInterval(() => {
|
||||
if (runStatus.isRunActive) {
|
||||
return;
|
||||
}
|
||||
void runStatus.syncLatest();
|
||||
}, PUBLICATIONS_RUN_STATUS_SYNC_INTERVAL_MS);
|
||||
}
|
||||
|
||||
function stopRunStatusSyncLoop(): void {
|
||||
if (runStatusSyncTimer === null) {
|
||||
return;
|
||||
}
|
||||
clearInterval(runStatusSyncTimer);
|
||||
runStatusSyncTimer = null;
|
||||
}
|
||||
|
||||
const selectedScholarName = computed(() => {
|
||||
const selectedId = Number(selectedScholarFilter.value);
|
||||
if (!Number.isInteger(selectedId) || selectedId <= 0) {
|
||||
|
|
@ -203,11 +226,12 @@ const filteredPublications = computed(() => {
|
|||
|
||||
const base = listState.value?.publications ?? [];
|
||||
const merged = [...stream, ...base];
|
||||
const seenIds = new Set();
|
||||
const seenKeys = new Set<string>();
|
||||
const deduped: typeof base = [];
|
||||
for (const item of merged) {
|
||||
if (!seenIds.has(item.publication_id)) {
|
||||
seenIds.add(item.publication_id);
|
||||
const key = publicationKey(item);
|
||||
if (!seenKeys.has(key)) {
|
||||
seenKeys.add(key);
|
||||
deduped.push(item);
|
||||
}
|
||||
}
|
||||
|
|
@ -234,14 +258,41 @@ function publicationSortValue(item: PublicationItem, key: PublicationSortKey): n
|
|||
if (key === "citations") {
|
||||
return item.citation_count;
|
||||
}
|
||||
if (key === "pdf_status") {
|
||||
if (item.pdf_url || item.pdf_status === "resolved") {
|
||||
return 4;
|
||||
}
|
||||
if (item.pdf_status === "running") {
|
||||
return 3;
|
||||
}
|
||||
if (item.pdf_status === "queued") {
|
||||
return 2;
|
||||
}
|
||||
if (item.pdf_status === "failed") {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
const timestamp = Date.parse(item.first_seen_at);
|
||||
return Number.isNaN(timestamp) ? 0 : timestamp;
|
||||
}
|
||||
|
||||
const sortedPublications = computed(() => {
|
||||
// Server already returns data in the correct sort order.
|
||||
// We just pass through the filtered/merged list without client-side re-sorting.
|
||||
return filteredPublications.value;
|
||||
const direction = sortDirection.value === "asc" ? 1 : -1;
|
||||
return [...filteredPublications.value].sort((left, right) => {
|
||||
const leftValue = publicationSortValue(left, sortKey.value);
|
||||
const rightValue = publicationSortValue(right, sortKey.value);
|
||||
let comparison = 0;
|
||||
if (typeof leftValue === "string" && typeof rightValue === "string") {
|
||||
comparison = textCollator.compare(leftValue, rightValue);
|
||||
} else {
|
||||
comparison = Number(leftValue) - Number(rightValue);
|
||||
}
|
||||
if (comparison !== 0) {
|
||||
return comparison * direction;
|
||||
}
|
||||
return right.publication_id - left.publication_id;
|
||||
});
|
||||
});
|
||||
|
||||
const visibleUnreadKeys = computed(() => {
|
||||
|
|
@ -271,6 +322,7 @@ const totalPages = computed(() => {
|
|||
});
|
||||
|
||||
const selectedCount = computed(() => selectedPublicationKeys.value.size);
|
||||
const totalCount = computed(() => listState.value?.total_count ?? 0);
|
||||
const visibleCount = computed(() => sortedPublications.value.length);
|
||||
const visibleUnreadCount = computed(() => visibleUnreadKeys.value.size);
|
||||
const visibleFavoriteCount = computed(
|
||||
|
|
@ -432,7 +484,7 @@ async function toggleSort(nextKey: PublicationSortKey): Promise<void> {
|
|||
sortDirection.value = sortDirection.value === "asc" ? "desc" : "asc";
|
||||
} else {
|
||||
sortKey.value = nextKey;
|
||||
sortDirection.value = nextKey === "first_seen" ? "desc" : "asc";
|
||||
sortDirection.value = nextKey === "first_seen" || nextKey === "pdf_status" ? "desc" : "asc";
|
||||
}
|
||||
currentPage.value = 1;
|
||||
publicationSnapshot.value = null;
|
||||
|
|
@ -800,9 +852,32 @@ watch(searchQuery, () => {
|
|||
|
||||
onMounted(() => {
|
||||
syncFiltersFromRoute();
|
||||
startRunStatusSyncLoop();
|
||||
void Promise.all([loadScholarFilters(), loadPublications(), runStatus.syncLatest()]);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
stopRunStatusSyncLoop();
|
||||
});
|
||||
|
||||
watch(
|
||||
() => runStatus.latestRun,
|
||||
async (nextRun, previousRun) => {
|
||||
const nextRunId = nextRun && (nextRun.status === "running" || nextRun.status === "resolving")
|
||||
? nextRun.id
|
||||
: null;
|
||||
const previousRunId = previousRun && (previousRun.status === "running" || previousRun.status === "resolving")
|
||||
? previousRun.id
|
||||
: null;
|
||||
if (nextRunId === null || nextRunId === previousRunId) {
|
||||
return;
|
||||
}
|
||||
publicationSnapshot.value = null;
|
||||
currentPage.value = 1;
|
||||
await loadPublications();
|
||||
},
|
||||
);
|
||||
|
||||
watch(
|
||||
() => [route.query.scholar, route.query.favorite, route.query.page],
|
||||
async () => {
|
||||
|
|
@ -1008,7 +1083,11 @@ watch(
|
|||
Scholar <span aria-hidden="true" class="sort-marker">{{ sortMarker('scholar') }}</span>
|
||||
</button>
|
||||
</th>
|
||||
<th scope="col" class="w-[8.5rem] whitespace-nowrap text-left font-semibold text-ink-primary">PDF</th>
|
||||
<th scope="col" class="w-[8.5rem] whitespace-nowrap">
|
||||
<button type="button" class="table-sort" @click="toggleSort('pdf_status')">
|
||||
PDF <span aria-hidden="true" class="sort-marker">{{ sortMarker('pdf_status') }}</span>
|
||||
</button>
|
||||
</th>
|
||||
<th scope="col" class="w-16 whitespace-nowrap">
|
||||
<button type="button" class="table-sort" @click="toggleSort('year')">
|
||||
Year <span aria-hidden="true" class="sort-marker">{{ sortMarker('year') }}</span>
|
||||
|
|
@ -1135,7 +1214,7 @@ watch(
|
|||
|
||||
<div class="flex flex-wrap items-center justify-between gap-2 border-t border-stroke-default pt-2 text-xs text-secondary">
|
||||
<span>
|
||||
visible {{ visibleCount }} · unread {{ visibleUnreadCount }} · favorites {{ visibleFavoriteCount }}
|
||||
total {{ totalCount }} · visible {{ visibleCount }} · unread {{ visibleUnreadCount }} · favorites {{ visibleFavoriteCount }}
|
||||
· selected {{ selectedCount }}
|
||||
</span>
|
||||
<div class="flex items-center gap-2">
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from "vue";
|
||||
|
||||
import AppPage from "@/components/layout/AppPage.vue";
|
||||
import AsyncStateGate from "@/components/patterns/AsyncStateGate.vue";
|
||||
|
|
@ -34,6 +34,7 @@ import {
|
|||
} from "@/features/scholars";
|
||||
import ScholarAvatar from "@/features/scholars/components/ScholarAvatar.vue";
|
||||
import { ApiRequestError } from "@/lib/api/errors";
|
||||
import { useRunStatusStore } from "@/stores/run_status";
|
||||
|
||||
const loading = ref(true);
|
||||
const saving = ref(false);
|
||||
|
|
@ -66,6 +67,10 @@ const successMessage = ref<string | null>(null);
|
|||
const SCHOLAR_ID_PATTERN = /^[a-zA-Z0-9_-]{12}$/;
|
||||
const URL_USER_PARAM_PATTERN = /(?:\?|&)user=([a-zA-Z0-9_-]{12})(?:&|#|$)/i;
|
||||
const nameSearchWip = true;
|
||||
const SCHOLARS_LIVE_SYNC_INTERVAL_MS = 4000;
|
||||
let scholarsLiveSyncTimer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
const runStatus = useRunStatusStore();
|
||||
|
||||
const trackedScholarIds = computed(() => new Set(scholars.value.map((item) => item.scholar_id)));
|
||||
const activeScholarSettings = computed(
|
||||
|
|
@ -260,14 +265,54 @@ function syncImageDrafts(): void {
|
|||
imageUrlDraftByScholarId.value = next;
|
||||
}
|
||||
|
||||
function applyScholarList(nextScholars: ScholarProfile[]): void {
|
||||
scholars.value = nextScholars;
|
||||
syncImageDrafts();
|
||||
}
|
||||
|
||||
function upsertScholar(profile: ScholarProfile): void {
|
||||
const existingIndex = scholars.value.findIndex((item) => item.id === profile.id);
|
||||
if (existingIndex < 0) {
|
||||
applyScholarList([profile, ...scholars.value]);
|
||||
return;
|
||||
}
|
||||
const next = [...scholars.value];
|
||||
next[existingIndex] = profile;
|
||||
applyScholarList(next);
|
||||
}
|
||||
|
||||
function stopScholarLiveSync(): void {
|
||||
if (scholarsLiveSyncTimer === null) {
|
||||
return;
|
||||
}
|
||||
clearInterval(scholarsLiveSyncTimer);
|
||||
scholarsLiveSyncTimer = null;
|
||||
}
|
||||
|
||||
function startScholarLiveSync(): void {
|
||||
if (scholarsLiveSyncTimer !== null) {
|
||||
return;
|
||||
}
|
||||
scholarsLiveSyncTimer = setInterval(() => {
|
||||
void refreshScholarsSilently();
|
||||
}, SCHOLARS_LIVE_SYNC_INTERVAL_MS);
|
||||
}
|
||||
|
||||
async function refreshScholarsSilently(): Promise<void> {
|
||||
try {
|
||||
applyScholarList(await listScholars());
|
||||
} catch (_error) {
|
||||
// Keep existing list when transient refresh fails.
|
||||
}
|
||||
}
|
||||
|
||||
async function loadScholars(): Promise<void> {
|
||||
loading.value = true;
|
||||
|
||||
try {
|
||||
scholars.value = await listScholars();
|
||||
syncImageDrafts();
|
||||
applyScholarList(await listScholars());
|
||||
} catch (error) {
|
||||
scholars.value = [];
|
||||
applyScholarList([]);
|
||||
if (error instanceof ApiRequestError) {
|
||||
errorMessage.value = error.message;
|
||||
errorRequestId.value = error.requestId;
|
||||
|
|
@ -360,7 +405,11 @@ async function onAddScholars(): Promise<void> {
|
|||
}
|
||||
|
||||
const settled = await Promise.allSettled(
|
||||
scholarIds.map((scholarId) => createScholar({ scholar_id: scholarId })),
|
||||
scholarIds.map(async (scholarId) => {
|
||||
const created = await createScholar({ scholar_id: scholarId });
|
||||
upsertScholar(created);
|
||||
return created;
|
||||
}),
|
||||
);
|
||||
|
||||
const failures: string[] = [];
|
||||
|
|
@ -399,7 +448,7 @@ async function onAddScholars(): Promise<void> {
|
|||
errorRequestId.value = requestIdFromFailures;
|
||||
}
|
||||
|
||||
await loadScholars();
|
||||
await refreshScholarsSilently();
|
||||
} catch (error) {
|
||||
if (error instanceof ApiRequestError) {
|
||||
errorMessage.value = error.message;
|
||||
|
|
@ -453,12 +502,12 @@ async function onAddCandidate(candidate: ScholarSearchCandidate): Promise<void>
|
|||
successMessage.value = null;
|
||||
|
||||
try {
|
||||
await createScholar({
|
||||
const created = await createScholar({
|
||||
scholar_id: candidate.scholar_id,
|
||||
profile_image_url: candidate.profile_image_url ?? undefined,
|
||||
});
|
||||
upsertScholar(created);
|
||||
successMessage.value = `${candidate.display_name} added.`;
|
||||
await loadScholars();
|
||||
} catch (error) {
|
||||
if (error instanceof ApiRequestError) {
|
||||
errorMessage.value = error.message;
|
||||
|
|
@ -608,6 +657,22 @@ async function onResetImage(profile: ScholarProfile): Promise<void> {
|
|||
onMounted(() => {
|
||||
void loadScholars();
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
stopScholarLiveSync();
|
||||
});
|
||||
|
||||
watch(
|
||||
() => runStatus.isLikelyRunning,
|
||||
(isRunning) => {
|
||||
if (isRunning) {
|
||||
startScholarLiveSync();
|
||||
return;
|
||||
}
|
||||
stopScholarLiveSync();
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue