forked from BRETT/BRETT
Keep thread navigation within the originating upload list
Record where an upload was opened from in a new useUploadNavContext state. When a tile is clicked on a user profile, the thread page passes that context to the upload detail API, which scopes the newer/older neighbors to that user's uploads. Arrow clicks reseed the context for the next thread, so the chain stays within the source list without a URL parameter. Threads opened directly (notification, reload) fall back to the global order. The breadcrumb reads the same context and shows the profile path for profile-originated threads, now including the thread id in the final crumb. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
@@ -55,8 +55,13 @@ export default defineEventHandler(async (event) => {
|
||||
.where(eq(comments.uploadId, id))
|
||||
.orderBy(asc(comments.createdAt))
|
||||
|
||||
// Nachbarn in Grid-Reihenfolge (createdAt desc, id desc als Tiebreak)
|
||||
// Nachbarn in Grid-Reihenfolge (createdAt desc, id desc als Tiebreak).
|
||||
// Kontext ?from=/user/<id> scopt die Navigation auf die Uploads dieses
|
||||
// Nutzers — so durchläuft man vom Profil aus nur dessen Uploads
|
||||
const sessionUser = await getSessionUser(event)
|
||||
const from = String(getQuery(event).from ?? '')
|
||||
const contextUserId = /^\/user\/(\d+)$/.exec(from)?.[1]
|
||||
const scopedToUser = contextUserId ? eq(uploads.userId, Number(contextUserId)) : undefined
|
||||
const commentIds = commentRows.map(c => c.id)
|
||||
const [reactionRows, uploadReactionRows, favRows, newerRows, olderRows, tagRows, attachmentRows, subscriptionRows] = await Promise.all([
|
||||
commentIds.length
|
||||
@@ -91,18 +96,24 @@ export default defineEventHandler(async (event) => {
|
||||
db
|
||||
.select({ id: uploads.id })
|
||||
.from(uploads)
|
||||
.where(or(
|
||||
gt(uploads.createdAt, upload.createdAt),
|
||||
and(eq(uploads.createdAt, upload.createdAt), gt(uploads.id, upload.id)),
|
||||
.where(and(
|
||||
or(
|
||||
gt(uploads.createdAt, upload.createdAt),
|
||||
and(eq(uploads.createdAt, upload.createdAt), gt(uploads.id, upload.id)),
|
||||
),
|
||||
scopedToUser,
|
||||
))
|
||||
.orderBy(asc(uploads.createdAt), asc(uploads.id))
|
||||
.limit(1),
|
||||
db
|
||||
.select({ id: uploads.id })
|
||||
.from(uploads)
|
||||
.where(or(
|
||||
lt(uploads.createdAt, upload.createdAt),
|
||||
and(eq(uploads.createdAt, upload.createdAt), lt(uploads.id, upload.id)),
|
||||
.where(and(
|
||||
or(
|
||||
lt(uploads.createdAt, upload.createdAt),
|
||||
and(eq(uploads.createdAt, upload.createdAt), lt(uploads.id, upload.id)),
|
||||
),
|
||||
scopedToUser,
|
||||
))
|
||||
.orderBy(desc(uploads.createdAt), desc(uploads.id))
|
||||
.limit(1),
|
||||
|
||||
Reference in New Issue
Block a user