Skip to content

Commit

Permalink
Pass locale in preview payload
Browse files Browse the repository at this point in the history
  • Loading branch information
benmerckx committed Nov 11, 2024
1 parent b504c41 commit 28f6770
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/adapter/next/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function createHandler<Driver extends AvailableDrivers>(
first: true,
select: Entry.url,
id: info.entryId,
locale: info.locale,
preview: payload ? {payload} : undefined
})
if (!url) return new Response('Not found', {status: 404})
Expand Down
1 change: 1 addition & 0 deletions src/backend/Handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const PrepareBody = object({
})

const PreviewBody = object({
locale: string.nullable,
entryId: string
})

Expand Down
1 change: 1 addition & 0 deletions src/backend/Previews.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface PreviewInfo {
locale: string | null
entryId: string
}

Expand Down
1 change: 1 addition & 0 deletions src/core/Preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface PreviewPayload {
export type PreviewRequest = PreviewPayload | {entry: EntryRow}

export interface PreviewUpdate {
locale: string | null
entryId: string
contentHash: string
status: string
Expand Down
6 changes: 5 additions & 1 deletion src/dashboard/atoms/EntryEditorAtoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ export function createEntryEditor(entryData: EntryData) {
const update = get(yUpdate)
const status = get(selectedStatus)
return encodePreviewPayload({
locale: activeVersion.locale,
entryId: activeVersion.id,
contentHash,
status: status,
Expand All @@ -753,7 +754,10 @@ export function createEntryEditor(entryData: EntryData) {

const previewToken = atom(async get => {
const client = get(clientAtom)
return client.previewToken({entryId: entryData.entryId})
return client.previewToken({
locale: activeVersion.locale,
entryId: entryData.entryId
})
})

return {
Expand Down
2 changes: 2 additions & 0 deletions src/preview/PreviewPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as encoding from 'lib0/encoding.js'

export function encodePreviewPayload(update: PreviewUpdate): Promise<string> {
const encoder = encoding.createEncoder()
encoding.writeVarString(encoder, update.locale ?? '')
encoding.writeVarString(encoder, update.entryId)
encoding.writeVarString(encoder, update.contentHash)
encoding.writeVarString(encoder, update.status)
Expand All @@ -17,6 +18,7 @@ export async function decodePreviewPayload(
): Promise<PreviewUpdate> {
const decoder = decoding.createDecoder(new Uint8Array(await decode(payload)))
return {
locale: decoding.readVarString(decoder) || null,
entryId: decoding.readVarString(decoder),
contentHash: decoding.readVarString(decoder),
status: decoding.readVarString(decoder),
Expand Down

0 comments on commit 28f6770

Please sign in to comment.