Add view on site button

This commit is contained in:
Justin Edmund 2025-06-12 03:28:34 -07:00
parent c615791090
commit c50b8e2e53
4 changed files with 44 additions and 39 deletions

View file

@ -236,6 +236,7 @@
show: formData.status !== 'password-protected' show: formData.status !== 'password-protected'
} }
]} ]}
viewUrl={project?.slug ? `/work/${project.slug}` : undefined}
/> />
{/if} {/if}
</div> </div>
@ -314,6 +315,7 @@
width: 250px; width: 250px;
display: flex; display: flex;
justify-content: flex-end; justify-content: flex-end;
gap: $unit-2x;
} }
} }
@ -336,6 +338,7 @@
} }
} }
.admin-container { .admin-container {
width: 100%; width: 100%;
margin: 0 auto; margin: 0 auto;

View file

@ -17,6 +17,7 @@
status: string status: string
show?: boolean show?: boolean
}> }>
viewUrl?: string
} }
let { let {
@ -25,7 +26,8 @@
disabled = false, disabled = false,
isLoading = false, isLoading = false,
primaryAction, primaryAction,
dropdownActions = [] dropdownActions = [],
viewUrl
}: Props = $props() }: Props = $props()
let isDropdownOpen = $state(false) let isDropdownOpen = $state(false)
@ -62,6 +64,9 @@
const availableActions = $derived( const availableActions = $derived(
dropdownActions.filter((action) => action.show !== false && action.status !== currentStatus) dropdownActions.filter((action) => action.show !== false && action.status !== currentStatus)
) )
const showViewInDropdown = $derived(viewUrl && currentStatus === 'published')
const hasDropdownContent = $derived(availableActions.length > 0 || showViewInDropdown)
</script> </script>
<div class="status-dropdown"> <div class="status-dropdown">
@ -74,7 +79,7 @@
{isLoading ? `${primaryAction.label.replace(/e$/, 'ing')}...` : primaryAction.label} {isLoading ? `${primaryAction.label.replace(/e$/, 'ing')}...` : primaryAction.label}
</Button> </Button>
{#if availableActions.length > 0} {#if hasDropdownContent}
<Button <Button
variant="ghost" variant="ghost"
iconOnly iconOnly
@ -100,6 +105,14 @@
{action.label} {action.label}
</DropdownItem> </DropdownItem>
{/each} {/each}
{#if showViewInDropdown}
{#if availableActions.length > 0}
<div class="dropdown-divider"></div>
{/if}
<a href={viewUrl} target="_blank" rel="noopener noreferrer" class="dropdown-item view-link">
View on site
</a>
{/if}
</DropdownMenuContainer> </DropdownMenuContainer>
{/if} {/if}
{/if} {/if}
@ -113,4 +126,28 @@
display: flex; display: flex;
gap: $unit-half; gap: $unit-half;
} }
.dropdown-divider {
height: 1px;
background-color: $grey-90;
margin: $unit-half 0;
}
.dropdown-item.view-link {
display: block;
width: 100%;
padding: $unit-2x $unit-3x;
background: none;
border: none;
text-align: left;
font-size: 0.875rem;
color: $grey-20;
cursor: pointer;
transition: background-color 0.2s ease;
text-decoration: none;
&:hover {
background-color: $grey-95;
}
}
</style> </style>

View file

@ -603,6 +603,7 @@
? { label: 'Save', status: 'published' } ? { label: 'Save', status: 'published' }
: { label: 'Publish', status: 'published' }} : { label: 'Publish', status: 'published' }}
dropdownActions={[{ label: 'Save as Draft', status: 'draft', show: status !== 'draft' }]} dropdownActions={[{ label: 'Save as Draft', status: 'draft', show: status !== 'draft' }]}
viewUrl={slug ? `/photos/${slug}` : undefined}
/> />
</div> </div>
{/if} {/if}
@ -768,22 +769,6 @@
} }
} }
.btn {
padding: $unit-2x $unit-3x;
border: none;
border-radius: 50px;
font-size: 0.925rem;
cursor: pointer;
transition: all 0.2s ease;
display: flex;
align-items: center;
gap: $unit;
&:disabled {
opacity: 0.6;
cursor: not-allowed;
}
}
.loading-container { .loading-container {
display: flex; display: flex;

View file

@ -366,6 +366,7 @@
? { label: 'Save', status: 'published' } ? { label: 'Save', status: 'published' }
: { label: 'Publish', status: 'published' }} : { label: 'Publish', status: 'published' }}
dropdownActions={[{ label: 'Save as Draft', status: 'draft', show: status !== 'draft' }]} dropdownActions={[{ label: 'Save as Draft', status: 'draft', show: status !== 'draft' }]}
viewUrl={slug ? `/universe/${slug}` : undefined}
/> />
</div> </div>
{/if} {/if}
@ -489,27 +490,6 @@
} }
} }
.btn {
padding: $unit-2x $unit-3x;
border: none;
border-radius: 50px;
font-size: 0.925rem;
cursor: pointer;
transition: all 0.2s ease;
display: flex;
align-items: center;
gap: $unit;
&:disabled {
opacity: 0.6;
cursor: not-allowed;
}
&.btn-small {
padding: $unit $unit-2x;
font-size: 0.875rem;
}
}
.dropdown-menu { .dropdown-menu {
position: absolute; position: absolute;