Media management
Media management workspace
open System
open FSharp.ViewEngine
open Acme.Components.Primitives
open Acme.Components.Application
open Acme.Components.Documentation
open type Html
open type Svg
open type Datastar
type ExamplePage =
| DependencyGraph
| ExecutionDetail
| FinancialReporting
| Messaging
| Operations
| Scheduling
| MediaManagement
type ReviewState =
| Setup
| Ready
| Loading
| Empty
| Failed
type ExampleQuery =
{ state: ReviewState
item: string
view: string
range: string }
let defaultQuery =
{ state = Ready
item = ""
view = ""
range = "" }
let slug =
function
| DependencyGraph -> "dependency-graph"
| ExecutionDetail -> "execution-detail"
| FinancialReporting -> "financial-reporting"
| Messaging -> "messaging"
| Operations -> "operations-dashboard"
| Scheduling -> "scheduling"
| MediaManagement -> "media-management"
let title =
function
| DependencyGraph -> "Dependency graph"
| ExecutionDetail -> "Execution detail"
| FinancialReporting -> "Financial reporting"
| Messaging -> "Messaging"
| Operations -> "Operations dashboard"
| Scheduling -> "Scheduling"
| MediaManagement -> "Media management"
let url page =
"/components/page-examples/" + slug page
let stateKey =
function
| Setup -> "setup"
| Ready -> "ready"
| Loading -> "loading"
| Empty -> "empty"
| Failed -> "error"
let queryUrl page query =
let pairs =
[ "state", stateKey query.state
"item", query.item
"view", query.view
"range", query.range ]
url page
+ "?"
+ (pairs
|> List.filter (snd >> String.IsNullOrEmpty >> not)
|> List.map (fun (key, value) -> key + "=" + Uri.EscapeDataString value)
|> String.concat "&")
let link (href: string) (label: string) : HtmlElement =
a {
_href href
_class
"font-medium text-[var(--fve-brand-text)] underline-offset-4 hover:underline focus-visible:outline-2 focus-visible:outline-[var(--fve-brand-ring)]"
label
}
// Ordinary consumer-authored anchors for compact page-header destinations.
let pageLink (href: string) (label: string) =
a {
_href href
_class
"inline-flex min-h-8 items-center justify-center rounded-[var(--fve-radius-control)] bg-[var(--fve-surface)] px-3 py-1.5 text-sm font-medium leading-5 text-[var(--fve-text)] ring-1 ring-inset ring-[var(--fve-border)] [&:not([readonly])]:not-disabled:not-aria-disabled:not-aria-busy:hover:bg-[linear-gradient(var(--fve-hover-wash),var(--fve-hover-wash))] [&:not([readonly])]:not-disabled:not-aria-disabled:not-aria-busy:active:bg-[linear-gradient(var(--fve-pressed-wash),var(--fve-pressed-wash))] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[var(--fve-brand-ring)]"
label
}
let section (heading: string) (content: HtmlElement) =
Section.create
(fveSectionHeader {
_label heading
_divider true
})
content
|> Section.render
let details (fields: (string * string) list) =
fveDescriptionList {
for label, value in fields do
fveDescriptionListItem {
_label label
value
}
_columns DescriptionListColumns.Three
}
let reviewStates page =
(if page = Operations then [ Setup, "Setup" ] else [])
@ [ Ready, "Populated"; Loading, "Loading"; Empty, "Empty"; Failed, "Error" ]
let stateContent page query content =
match query.state with
| Setup
| Ready -> content
| Loading ->
div {
_class "p-8"
let label = "Loading " + (title page).ToLowerInvariant()
fveLoadingIndicator {
_ariaLabel label
label
}
}
| Empty ->
let heading, description, action =
match page with
| DependencyGraph ->
"No dependencies found", "There are no dependencies for this selection.", "View dependencies"
| ExecutionDetail ->
"No execution selected",
"Choose an execution to inspect its timing and logs.",
"View latest execution"
| FinancialReporting ->
"No activity for this period",
"Choose a period with recorded balances and transactions.",
"View recent activity"
| Messaging ->
"No messages in this conversation",
"Choose a conversation to read its messages.",
"View conversations"
| Operations -> "No sessions scheduled", "Check the schedule for upcoming sessions.", "View schedule"
| Scheduling ->
"No sessions in this period",
"Return to the current period to see upcoming sessions.",
"View current schedule"
| MediaManagement ->
"No media in this selection", "Browse the library to choose an asset.", "Browse media"
fveEmptyState {
_label heading
_description description
fveEmptyStateActions {
link (queryUrl (if page = Operations then Scheduling else page) { query with state = Ready }) action
}
}
| Failed ->
fveNotice {
_id "workspace-error"
_label "This view could not be loaded"
p { "Your selection is preserved. Try loading it again." }
_color Color.Error
fveNoticeActions { link (queryUrl page { query with state = Ready }) "Try again" }
}
/// Place durable workspace identity above the scrollable destination list.
let sideNavWorkspace (name: string) =
div {
p {
_class "text-xs font-semibold uppercase tracking-wide text-[var(--fve-muted-text)]"
"Workspace"
}
p {
_class "mt-1 truncate text-sm font-semibold"
name
}
}
let workspace page heading subtitle canvas (actions: HtmlElement list) content =
let product, workspaceName, destinations =
match page with
| DependencyGraph
| ExecutionDetail ->
"Relay", "Customer analytics", [ DependencyGraph, "Dependencies"; ExecutionDetail, "Executions" ]
| FinancialReporting -> "Ledger", "Meier Made", [ FinancialReporting, "Overview" ]
| Messaging -> "Gather", "Northwind Outdoor", [ Messaging, "Messages" ]
| _ ->
"Fieldwork",
"Northwind Outdoor",
[ Operations, "Overview"; Scheduling, "Schedule"; MediaManagement, "Media" ]
let items =
[ for destination, label in destinations ->
fveSideNavItem {
_href (url destination)
label
} ]
let navigation =
fveSideNav {
_id (slug page + "-nav")
_ariaLabel (product + " navigation")
fveSideNavHeader { _label product }
fveSideNavContent { yield! items }
_value (url page)
Html._width SideNavWidth.Narrow
fveSideNavContext { sideNavWorkspace workspaceName }
fveSideNavFooter {
div {
_class "flex min-w-0 items-center gap-3"
fveAvatar {
_ariaLabel "Andy Meier"
"AM"
}
p {
_class "truncate text-sm font-medium"
"Andy Meier"
}
}
}
}
let header =
fvePageHeader {
_label heading
_description subtitle
if not (List.isEmpty actions) then
fvePageHeaderActions {
div {
_id (slug page + "-actions")
_class "flex flex-wrap items-center gap-3"
for action in actions do
action
}
}
}
let topBar =
fvePageTopBar {
div {
_class "flex min-w-0 flex-1 items-center"
fveBreadcrumbs {
_id (slug page + "-breadcrumbs")
_ariaLabel (product + " breadcrumb")
fveBreadcrumbItem {
_href (url page)
product
}
fveBreadcrumbItem {
_href (url page)
heading
}
}
}
}
let body =
Page.create header content
|> Page.withWidth PageWidth.Full
|> Page.withBodyLayout (
if canvas then
PageBodyLayout.Canvas
else
PageBodyLayout.Padded
)
|> Page.render
let framedBody =
div {
_class "flex h-full min-h-0 flex-col"
div {
_class "hidden shrink-0 md:block"
topBar
}
div {
_class "min-h-0 flex-1"
body
}
}
(AppShell.create ((slug page + "-shell")) (navigation) (framedBody)
|> AppShell.withTheme (
(ComponentsTheme.sky
|> ComponentsTheme.withDensity Density.Compact
|> ComponentsTheme.withControlSize Size.Small)
)
|> AppShell.withBoundary (AppShellBoundary.Container)
|> AppShell.asPreview ((product + " workspace"))
|> AppShell.render)
type ScheduledEvent =
{ id: string
name: string
date: DateOnly
time: string
start: TimeOnly
finish: TimeOnly
people: string
kind: string
photo: string }
let scheduledEvents =
[ { id = "lesson-201"
name = "Coastal trail lesson"
date = DateOnly(2026, 9, 17)
time = "10:00–11:30 AM"
start = TimeOnly(10, 0)
finish = TimeOnly(11, 30)
people = "Maya and Sam · Instructor: Andy Meier"
kind = "Lesson"
photo = "photo-303" }
{ id = "camp-017"
name = "Beginner riding camp"
date = DateOnly(2026, 9, 17)
time = "10:30 AM–12:00 PM"
start = TimeOnly(10, 30)
finish = TimeOnly(12, 0)
people = "3 riders · Instructor: Jordan"
kind = "Camp"
photo = "photo-301" }
{ id = "lesson-202"
name = "Cornering fundamentals"
date = DateOnly(2026, 9, 18)
time = "9:00–10:00 AM"
start = TimeOnly(9, 0)
finish = TimeOnly(10, 0)
people = "Riley · Instructor: Andy Meier"
kind = "Lesson"
photo = "photo-302" }
{ id = "ride-019"
name = "Open track practice"
date = DateOnly(2026, 9, 19)
time = "1:00–3:00 PM"
start = TimeOnly(13, 0)
finish = TimeOnly(15, 0)
people = "6 riders · Supervisor: Jordan"
kind = "Practice"
photo = "photo-304" }
{ id = "return-020"
name = "Equipment return"
date = DateOnly(2026, 9, 24)
time = "4:00–4:30 PM"
start = TimeOnly(16, 0)
finish = TimeOnly(16, 30)
people = "Equipment team · Andy Meier"
kind = "Equipment"
photo = "photo-304" } ]
let eventUrl event =
queryUrl Scheduling { defaultQuery with item = event.id }
type WorkspacePhoto =
{ id: string
name: string
source: string
alt: string
eventId: string }
let initialPhotos =
[ { id = "photo-301"
name = "Social card"
source = "/social-card.png"
alt = "FSharp.ViewEngine — Typed HTML views for F#"
eventId = "camp-017" }
{ id = "photo-302"
name = "App icon"
source = "/android-chrome-512x512.png"
alt = "FSharp.ViewEngine blue code-mark icon"
eventId = "lesson-202" }
{ id = "photo-303"
name = "Touch icon"
source = "/apple-touch-icon.png"
alt = "FSharp.ViewEngine blue code-mark touch icon"
eventId = "lesson-201" }
{ id = "photo-304"
name = "Browser icon"
source = "/favicon-32x32.png"
alt = "FSharp.ViewEngine blue code-mark browser icon"
eventId = "ride-019" }
{ id = "photo-305"
name = "Small favicon"
source = "/favicon-16x16.png"
alt = "FSharp.ViewEngine blue code-mark favicon"
eventId = "camp-017" }
{ id = "photo-306"
name = "Vector logo"
source = "/logo.svg"
alt = "FSharp.ViewEngine code-mark logo"
eventId = "lesson-201" } ]
let uploadedPhoto =
{ id = "photo-uploaded"
name = "Uploaded fixture preview"
source = "/images/page-examples/violet.png"
alt = "Solid violet background used for the upload success fixture"
eventId = "" }
let photosFor query =
if query.item = uploadedPhoto.id || query.view = "uploaded" then
initialPhotos @ [ uploadedPhoto ]
else
initialPhotos
let mediaEditor (photo: WorkspacePhoto) (feedback: string) =
div {
_id "media-editor"
_class "grid gap-6 lg:grid-cols-2"
figure {
img {
_src photo.source
_alt photo.alt
_class "aspect-video w-full rounded-xl object-cover"
}
figcaption {
_class "mt-3 text-xs text-[var(--fve-muted-text)]"
photo.name
}
}
form {
_method "post"
_action (url MediaManagement + "/save?item=" + photo.id)
_class "grid content-start gap-5"
fveField {
fveLabel {
_for "name"
"Asset name"
}
fveInput {
_id "name"
_name "name"
_value photo.name
_required true
_maxlength 120
}
}
fveField {
fveLabel {
_for "alt"
"Image description"
}
fveTextarea {
_id "alt"
_name "alt"
_value photo.alt
_rows 3
_required true
_maxlength 500
_ariaDescribedby (String.concat " " [ ("alt") + "-description" ])
}
fveFieldDescription {
_id ("alt" + "-description")
"Describe the image for people who cannot see it."
}
}
div {
_role "status"
_class "text-sm text-[var(--fve-muted-text)]"
feedback
}
div {
_class "flex flex-wrap items-center gap-3"
fveButton {
_color Color.Primary
_variant ButtonVariant.Solid
_type "submit"
"Save changes"
}
link (url MediaManagement) "Back to media"
}
match scheduledEvents |> List.tryFind (fun event -> event.id = photo.eventId) with
| Some event -> link (eventUrl event) ("Related session: " + event.name)
| None -> ()
}
}
let mediaManagement query =
let photos = photosFor query
let selected =
photos |> List.tryFind (fun (photo: WorkspacePhoto) -> photo.id = query.item)
let uploadBody =
div {
_class "grid gap-5"
form {
_id "media-upload-form"
_method "post"
_action (url MediaManagement + "/upload")
_class "grid gap-5"
fveField {
fveLabel {
_for "media-upload-name"
"Asset name"
}
fveInput {
_id "media-upload-name"
_name "name"
_required true
_maxlength 120
}
}
fveField {
fveLabel {
_for "media-upload-description"
"Image description"
}
fveTextarea {
_id "media-upload-description"
_name "alt"
_rows 3
_required true
_maxlength 500
}
}
if query.view = "upload-error" then
p {
_role "alert"
_class "text-sm text-[var(--fve-critical-text)]"
"Provide a name and image description."
}
}
fveField {
fveLabel {
_for "media-upload-image"
"Image file"
}
fveFileSelection {
_id "media-upload-image"
_name "image"
_accept "image/jpeg,image/png,image/webp"
_ariaDescribedby "media-upload-image-help"
}
fveFieldDescription {
_id "media-upload-image-help"
"Selected files stay in your browser. This documentation fixture never submits or stores their contents."
}
}
}
let uploadDrawer =
fveDrawer {
_id "media-upload-drawer"
_label "Upload asset"
uploadBody
_description "Review a safe upload workflow using a repository-owned success fixture."
_initialFocus "media-upload-name"
fveDrawerFooter {
fragment {
fveButton {
_dataOn ("click", "document.getElementById('media-upload-drawer')?.close()")
"Cancel"
}
fveButton {
_color Color.Primary
_variant ButtonVariant.Solid
_type "submit"
_form "media-upload-form"
"Upload"
}
}
}
}
let uploadAction =
fveButton {
_color Color.Primary
_variant ButtonVariant.Solid
_dataOn (
"click",
"document.getElementById('media-upload-drawer')?.showModal(); queueMicrotask(() => document.getElementById('media-upload-name')?.focus())"
)
_id "media-upload-drawer-trigger"
_ariaHaspopup "dialog"
_ariaControls "media-upload-drawer"
"Upload"
}
let content, heading =
match selected with
| Some photo ->
mediaEditor
photo
(if query.view = "uploaded" then
"Demo image added. The selected local file was not submitted."
elif query.view = "saved" then
"Changes validated. This resettable example continues to use seeded metadata."
elif query.view = "invalid" then
"Check the name and description. Submitted values are not retained."
else
""),
photo.name
| None ->
let assets =
[ for photo in photos ->
MediaAsset.create
photo.id
photo.name
photo.source
photo.alt
(queryUrl MediaManagement { defaultQuery with item = photo.id })
|> MediaAsset.withDetail ("Session · " + photo.eventId) ]
div {
_class "grid gap-6"
MediaLibrary.create "fieldwork-photos" "Session assets" "photoIds" assets
|> MediaLibrary.render id
if query.view = "upload-error" then
div {
_class "hidden"
_dataEffect
"(() => { const drawer = document.getElementById('media-upload-drawer'); if (drawer && !drawer.open) drawer.showModal(); queueMicrotask(() => document.getElementById('media-upload-name')?.focus()) })()"
}
uploadDrawer
},
"Media"
let actions =
[ if query.state = Ready && selected.IsNone then
uploadAction ]
workspace MediaManagement heading "Session assets" false actions (stateContent MediaManagement query content)
div { _class "h-[44rem]"; mediaManagement defaultQuery }
|> Browser.create
|> Browser.withAddress "https://fve.meiermade.com/components/page-examples/media-management?state=ready"
|> Browser.render
|> Fixture.create "page-workspace" "Workspace" "/components/page-examples/media-management?state=ready"
|> Fixture.withFullscreenContent (mediaManagement defaultQuery)
|> Fixture.render
