|
17 | 17 | import { useEffect, useState } from 'react'; |
18 | 18 | import { useLocation, useNavigate } from 'react-router-dom'; |
19 | 19 | import { Eye, X, Rocket, GitCompareArrows } from 'lucide-react'; |
20 | | -import { Button } from '@object-ui/components'; |
| 20 | +import { Button, cn } from '@object-ui/components'; |
21 | 21 | import { useObjectTranslation } from '@object-ui/i18n'; |
22 | 22 | import { usePreviewDrafts, markPreviewExit, PREVIEW_QUERY_FLAG } from './PreviewModeContext'; |
23 | 23 | import { usePublishAllDrafts } from './usePublishAllDrafts'; |
@@ -77,34 +77,55 @@ export function DraftPreviewBar() { |
77 | 77 | setTimeout(() => { try { window.location.reload(); } catch { /* ignore */ } }, 300); |
78 | 78 | }; |
79 | 79 |
|
| 80 | + // Under the auto-publish posture (and any time a draft preview is opened with |
| 81 | + // nothing staged) there are zero pending drafts. Claiming "nothing is live |
| 82 | + // until you publish" and offering a Publish button then is both false and a |
| 83 | + // no-op, so the bar drops the publish affordance and softens to a neutral |
| 84 | + // preview indicator. An UNKNOWN count (null — still loading or the fetch |
| 85 | + // failed) keeps the publish path: we only relax when we KNOW the count is zero. |
| 86 | + const noChanges = pendingCount === 0; |
| 87 | + |
80 | 88 | return ( |
81 | 89 | <div |
82 | | - className="sticky top-0 z-40 flex items-center gap-3 border-b border-amber-300/70 bg-amber-50 px-4 py-2 text-sm text-amber-900 dark:border-amber-700/60 dark:bg-amber-950/40 dark:text-amber-200" |
| 90 | + className={cn( |
| 91 | + 'sticky top-0 z-40 flex items-center gap-3 border-b px-4 py-2 text-sm', |
| 92 | + noChanges |
| 93 | + ? 'border-slate-200 bg-slate-50 text-slate-700 dark:border-slate-700/60 dark:bg-slate-900/40 dark:text-slate-300' |
| 94 | + : 'border-amber-300/70 bg-amber-50 text-amber-900 dark:border-amber-700/60 dark:bg-amber-950/40 dark:text-amber-200', |
| 95 | + )} |
83 | 96 | data-testid="draft-preview-bar" |
84 | 97 | > |
85 | 98 | <Eye className="h-4 w-4 shrink-0" /> |
86 | 99 | <p className="min-w-0 flex-1 truncate"> |
87 | | - {t('preview.draftBar.message', { |
88 | | - defaultValue: 'Draft preview — you are seeing unpublished changes. Nothing here is live until you publish.', |
89 | | - })} |
| 100 | + {noChanges |
| 101 | + ? t('preview.draftBar.messageClean', { |
| 102 | + defaultValue: 'Draft preview — no unpublished changes; everything here is already live.', |
| 103 | + }) |
| 104 | + : t('preview.draftBar.message', { |
| 105 | + defaultValue: 'Draft preview — you are seeing unpublished changes. Nothing here is live until you publish.', |
| 106 | + })} |
90 | 107 | </p> |
91 | | - <Button |
92 | | - size="sm" |
93 | | - variant="outline" |
94 | | - onClick={() => setChangesOpen(true)} |
95 | | - data-testid="draft-preview-changes" |
96 | | - > |
97 | | - <GitCompareArrows className="mr-1 h-3.5 w-3.5" /> |
98 | | - {t('preview.draftBar.changes', { defaultValue: 'Changes' })} |
99 | | - {typeof pendingCount === 'number' ? ` (${pendingCount})` : ''} |
100 | | - </Button> |
101 | | - <Button size="sm" onClick={publish} disabled={publishing} data-testid="draft-preview-publish"> |
102 | | - <Rocket className="mr-1 h-3.5 w-3.5" /> |
103 | | - {publishing |
104 | | - ? t('preview.draftBar.publishing', { defaultValue: 'Publishing…' }) |
105 | | - : t('preview.draftBar.publish', { defaultValue: 'Publish' })} |
106 | | - </Button> |
107 | | - <DraftChangesPanel open={changesOpen} onOpenChange={setChangesOpen} /> |
| 108 | + {!noChanges && ( |
| 109 | + <> |
| 110 | + <Button |
| 111 | + size="sm" |
| 112 | + variant="outline" |
| 113 | + onClick={() => setChangesOpen(true)} |
| 114 | + data-testid="draft-preview-changes" |
| 115 | + > |
| 116 | + <GitCompareArrows className="mr-1 h-3.5 w-3.5" /> |
| 117 | + {t('preview.draftBar.changes', { defaultValue: 'Changes' })} |
| 118 | + {typeof pendingCount === 'number' ? ` (${pendingCount})` : ''} |
| 119 | + </Button> |
| 120 | + <Button size="sm" onClick={publish} disabled={publishing} data-testid="draft-preview-publish"> |
| 121 | + <Rocket className="mr-1 h-3.5 w-3.5" /> |
| 122 | + {publishing |
| 123 | + ? t('preview.draftBar.publishing', { defaultValue: 'Publishing…' }) |
| 124 | + : t('preview.draftBar.publish', { defaultValue: 'Publish' })} |
| 125 | + </Button> |
| 126 | + <DraftChangesPanel open={changesOpen} onOpenChange={setChangesOpen} /> |
| 127 | + </> |
| 128 | + )} |
108 | 129 | <Button size="sm" variant="outline" onClick={exit} data-testid="draft-preview-exit"> |
109 | 130 | <X className="mr-1 h-3.5 w-3.5" /> |
110 | 131 | {t('preview.draftBar.exit', { defaultValue: 'Exit preview' })} |
|
0 commit comments