From f2e5ad97aba56cbff582a00ffd8f20ca770e998e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Tue, 13 Feb 2024 18:27:48 +0100 Subject: [PATCH] Show button to share feedback about GitBook Open when in preview mode (#149) * Show button to share feedback * Lint --- src/app/[spaceId]/(content)/layout.tsx | 4 +- src/components/AdminToolbar/AdminToolbar.tsx | 55 +++++++++++++++----- src/middleware.ts | 1 + 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/app/[spaceId]/(content)/layout.tsx b/src/app/[spaceId]/(content)/layout.tsx index e09df154c..3ded215b4 100644 --- a/src/app/[spaceId]/(content)/layout.tsx +++ b/src/app/[spaceId]/(content)/layout.tsx @@ -60,9 +60,7 @@ export default async function ContentLayout(props: { ) : null} - {content.revisionId || content.changeRequestId ? ( - - ) : null} + ); } diff --git a/src/components/AdminToolbar/AdminToolbar.tsx b/src/components/AdminToolbar/AdminToolbar.tsx index d1b63bc96..6e9d6ffa9 100644 --- a/src/components/AdminToolbar/AdminToolbar.tsx +++ b/src/components/AdminToolbar/AdminToolbar.tsx @@ -1,3 +1,5 @@ +import { Space } from '@gitbook/api'; +import { headers } from 'next/headers'; import React from 'react'; import { ContentPointer, getChangeRequest, getRevision, getRevisionPages } from '@/lib/api'; @@ -5,13 +7,40 @@ import { tcls } from '@/lib/tailwind'; interface AdminToolbarProps { content: ContentPointer; + space: Space; } /** * Toolbar with information for the content admin when previewing a revision or change-request. */ export function AdminToolbar(props: AdminToolbarProps) { - const { content } = props; + const { content, space } = props; + const headersSet = headers(); + + const toolbar = (() => { + if (content.changeRequestId) { + return ( + + ); + } + + if (content.revisionId) { + return ; + } + + if (headersSet.get('x-gitbook-mode') === 'multi-id') { + return ; + } + + return null; + })(); + + if (!toolbar) { + return null; + } return (
- - {content.changeRequestId ? ( - - ) : null} - {content.revisionId ? ( - - ) : null} - + {toolbar}
); } @@ -71,6 +90,18 @@ async function RevisionToolbar(props: { spaceId: string; revisionId: string }) { ); } +async function ShareFeedbackToolbar(props: { space: Space }) { + const { space } = props; + + return ( + + Share feedback about the new version + + ); +} + function ToolbarButton(props: { href: string; children: React.ReactNode }) { const { href, children } = props; diff --git a/src/middleware.ts b/src/middleware.ts index e674a957d..5ea107ee4 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -157,6 +157,7 @@ export async function middleware(request: NextRequest) { headers.set('x-forwarded-host', inputURL.host); headers.set('origin', inputURL.origin); headers.set('x-gitbook-token', resolved.apiToken); + headers.set('x-gitbook-mode', mode); headers.set('x-gitbook-origin-basepath', originBasePath); headers.set('x-gitbook-basepath', joinPath(originBasePath, resolved.basePath)); if (resolved.revision) {