mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Hide preview select for design/announcement settings (#16721)
no issue - Hide post preview select if there is no published posts yet. --- <!-- Leave the line below if you'd like GitHub Copilot to generate a summary from your commit --> copilot:summary
This commit is contained in:
parent
dc1ff890a0
commit
7ade895ce7
3 changed files with 53 additions and 31 deletions
|
@ -30,13 +30,26 @@ export default class ThemeManagementService extends Service {
|
||||||
|
|
||||||
allPosts = this.store.peekAll('post');
|
allPosts = this.store.peekAll('post');
|
||||||
|
|
||||||
availablePreviewTypes = [{
|
get availablePreviewTypes() {
|
||||||
name: 'homepage',
|
const previewTypes = [{
|
||||||
label: 'Homepage'
|
name: 'homepage',
|
||||||
}, {
|
label: 'Homepage'
|
||||||
name: 'post',
|
}];
|
||||||
label: 'Post'
|
|
||||||
}];
|
// in case we haven't loaded any posts so far
|
||||||
|
if (!this.latestPublishedPost) {
|
||||||
|
this.loadLastPostTask.perform();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.latestPublishedPost) {
|
||||||
|
previewTypes.push({
|
||||||
|
name: 'post',
|
||||||
|
label: 'Post'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return previewTypes;
|
||||||
|
}
|
||||||
|
|
||||||
get latestPublishedPost() {
|
get latestPublishedPost() {
|
||||||
return this.allPosts.toArray().filterBy('status', 'published').sort((a, b) => {
|
return this.allPosts.toArray().filterBy('status', 'published').sort((a, b) => {
|
||||||
|
@ -170,6 +183,11 @@ export default class ThemeManagementService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@task
|
||||||
|
*loadLastPostTask() {
|
||||||
|
yield this.store.query('post', {filter: 'status:published', order: 'published_at DESC', limit: 1});
|
||||||
|
}
|
||||||
|
|
||||||
@task
|
@task
|
||||||
*updatePreviewHtmlTask() {
|
*updatePreviewHtmlTask() {
|
||||||
// skip during testing because we don't have mocks for the front-end
|
// skip during testing because we don't have mocks for the front-end
|
||||||
|
@ -182,10 +200,10 @@ export default class ThemeManagementService extends Service {
|
||||||
if (this.previewType === 'post') {
|
if (this.previewType === 'post') {
|
||||||
// in case we haven't loaded any posts so far
|
// in case we haven't loaded any posts so far
|
||||||
if (!this.latestPublishedPost) {
|
if (!this.latestPublishedPost) {
|
||||||
yield this.store.query('post', {filter: 'status:published', order: 'published_at DESC', limit: 1});
|
this.loadLastPostTask.perform();
|
||||||
}
|
}
|
||||||
|
|
||||||
frontendUrl = this.latestPublishedPost.url;
|
frontendUrl = this.latestPublishedPost?.url || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
const previewResponse = yield this.frontend.fetch(frontendUrl, {
|
const previewResponse = yield this.frontend.fetch(frontendUrl, {
|
||||||
|
|
|
@ -2,17 +2,19 @@
|
||||||
<GhCanvasHeader class="gh-canvas-header">
|
<GhCanvasHeader class="gh-canvas-header">
|
||||||
<h2 class="gh-canvas-title">Announcement bar</h2>
|
<h2 class="gh-canvas-title">Announcement bar</h2>
|
||||||
<section class="view-actions">
|
<section class="view-actions">
|
||||||
<div class="gh-select gh-preview-page-selector">
|
{{#if (gt this.themeManagement.availablePreviewTypes.length 1)}}
|
||||||
<OneWaySelect
|
<div class="gh-select gh-preview-page-selector">
|
||||||
@value={{this.themeManagement.previewType}}
|
<OneWaySelect
|
||||||
@options={{this.themeManagement.availablePreviewTypes}}
|
@value={{this.themeManagement.previewType}}
|
||||||
@optionValuePath="name"
|
@options={{this.themeManagement.availablePreviewTypes}}
|
||||||
@optionLabelPath="label"
|
@optionValuePath="name"
|
||||||
@optionTargetPath="name"
|
@optionLabelPath="label"
|
||||||
@update={{this.themeManagement.setPreviewType}}
|
@optionTargetPath="name"
|
||||||
/>
|
@update={{this.themeManagement.setPreviewType}}
|
||||||
{{svg-jar "arrow-down-small"}}
|
/>
|
||||||
</div>
|
{{svg-jar "arrow-down-small"}}
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
<div class="gh-contentfilter gh-btn-group">
|
<div class="gh-contentfilter gh-btn-group">
|
||||||
<button type="button" class="gh-btn gh-design-preview-mode {{if this.isDesktopPreview "gh-btn-group-selected"}}" {{on "click" (fn this.setPreviewSize "desktop")}} data-test-button="desktop-preview"><span>{{svg-jar "desktop"}}</span></button>
|
<button type="button" class="gh-btn gh-design-preview-mode {{if this.isDesktopPreview "gh-btn-group-selected"}}" {{on "click" (fn this.setPreviewSize "desktop")}} data-test-button="desktop-preview"><span>{{svg-jar "desktop"}}</span></button>
|
||||||
|
|
|
@ -2,17 +2,19 @@
|
||||||
<GhCanvasHeader class="gh-canvas-header">
|
<GhCanvasHeader class="gh-canvas-header">
|
||||||
<h2 class="gh-canvas-title">Site design</h2>
|
<h2 class="gh-canvas-title">Site design</h2>
|
||||||
<section class="view-actions">
|
<section class="view-actions">
|
||||||
<div class="gh-select gh-preview-page-selector">
|
{{#if (gt this.themeManagement.availablePreviewTypes.length 1)}}
|
||||||
<OneWaySelect
|
<div class="gh-select gh-preview-page-selector">
|
||||||
@value={{this.themeManagement.previewType}}
|
<OneWaySelect
|
||||||
@options={{this.themeManagement.availablePreviewTypes}}
|
@value={{this.themeManagement.previewType}}
|
||||||
@optionValuePath="name"
|
@options={{this.themeManagement.availablePreviewTypes}}
|
||||||
@optionLabelPath="label"
|
@optionValuePath="name"
|
||||||
@optionTargetPath="name"
|
@optionLabelPath="label"
|
||||||
@update={{this.themeManagement.setPreviewType}}
|
@optionTargetPath="name"
|
||||||
/>
|
@update={{this.themeManagement.setPreviewType}}
|
||||||
{{svg-jar "arrow-down-small"}}
|
/>
|
||||||
</div>
|
{{svg-jar "arrow-down-small"}}
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
<div class="gh-contentfilter gh-btn-group">
|
<div class="gh-contentfilter gh-btn-group">
|
||||||
<button type="button" class="gh-btn gh-design-preview-mode {{if this.isDesktopPreview "gh-btn-group-selected"}}" {{on "click" (fn this.setPreviewSize "desktop")}} data-test-button="desktop-preview"><span>{{svg-jar "desktop"}}</span></button>
|
<button type="button" class="gh-btn gh-design-preview-mode {{if this.isDesktopPreview "gh-btn-group-selected"}}" {{on "click" (fn this.setPreviewSize "desktop")}} data-test-button="desktop-preview"><span>{{svg-jar "desktop"}}</span></button>
|
||||||
|
|
Loading…
Add table
Reference in a new issue