Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,10 @@ SMTP_FROM=

# Logging
RUST_LOG=info

# App UI preview (dev server only)
# Open /dev/app-ui as the owner to see a locally built app UI in the platform's frame.
# Absolute folder with the app's built UI (its index.html and assets).
# APP_UI_DEV_DIR=/home/you/my-app/dist/ui
# Optional loopback dev host of the app that answers its UI operations.
# APP_UI_DEV_API=http://127.0.0.1:8787/dev/v1/platform-call
70 changes: 70 additions & 0 deletions web/src/features/AppUi/Components/AppDialogSurfaceModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { useMemo, useState, type ReactNode } from 'react'

import { buttonClassName } from '@/shared/Buttons/buttonStyles.ts'
import useTranslationStore from '@/shared/Language/Hooks/useTranslationStore.ts'
import { Modal } from '@/shared/Modal/index.tsx'
import { AppDialogSurfaceContext } from '../appDialogSurfaceContext.ts'
import type { AppDialogChrome } from '../Types/app-dialog-surface.types.ts'

/**
* A platform dialog an app frame is drawn in. An app drawn with the UI kit whose root is a dialog
* fills its title, navigation and footer; otherwise the dialog shows `title`, `description` and
* its own close button around the frame.
*/
export default function AppDialogSurfaceModal({
open,
onOpenChange,
title,
description,
children,
}: {
readonly open: boolean
readonly onOpenChange: (open: boolean) => void
readonly title: string
readonly description: string
readonly children: ReactNode
}) {
const { t } = useTranslationStore()
const [chrome, setChrome] = useState<AppDialogChrome | null>(null)
const [navigation, setNavigation] = useState<HTMLDivElement | null>(null)
const [footer, setFooter] = useState<HTMLDivElement | null>(null)
const surface = useMemo(
() => ({ setChrome, navigation, footer, close: () => onOpenChange(false) }),
[footer, navigation, onOpenChange],
)
// The user closed the dialog: the app's root dialog hears of it before the platform closes it.
const close = () => {
chrome?.onClose()
onOpenChange(false)
}

return (
<Modal
open={open}
onOpenChange={(next) => {
if (next) onOpenChange(true)
else close()
}}
closeDisabled={chrome?.closeDisabled ?? false}
title={chrome?.heading ?? title}
description={chrome?.description ?? description}
size="xl"
fixedHeight
height="tall"
navigation={chrome?.navigation ? <div ref={setNavigation} /> : undefined}
footer={
chrome?.footer ? (
<div ref={setFooter} className="contents" />
) : (
<button type="button" className={buttonClassName('secondary')} onClick={close}>
{t('appUi.hostTable.close')}
</button>
)
}
>
<div className={chrome ? 'h-full' : 'h-full p-4'}>
<AppDialogSurfaceContext value={surface}>{children}</AppDialogSurfaceContext>
</div>
</Modal>
)
}
69 changes: 15 additions & 54 deletions web/src/features/AppUi/Components/AppHostActionDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { useMemo, useState } from 'react'

import { buttonClassName } from '@/shared/Buttons/buttonStyles.ts'
import useTranslationStore from '@/shared/Language/Hooks/useTranslationStore.ts'
import { Modal } from '@/shared/Modal/index.tsx'
import AppUiFrame from '../AppUiFrame.tsx'
import { AppDialogSurfaceContext } from '../appDialogSurfaceContext.ts'
import useAppHostActionDialogLogic from '../Hooks/useAppHostActionDialogLogic.ts'
import type { AppHostActionDialogProps } from '../Types/app-host-table.types.ts'
import type { AppDialogChrome } from '../Types/app-dialog-surface.types.ts'
import AppDialogSurfaceModal from './AppDialogSurfaceModal.tsx'

/**
* A host row action of an app, opened in a platform dialog for that host. An app drawn with the UI
Expand All @@ -16,60 +11,26 @@ import type { AppDialogChrome } from '../Types/app-dialog-surface.types.ts'
export default function AppHostActionDialog(props: AppHostActionDialogProps) {
const { t } = useTranslationStore()
const { state, handler } = useAppHostActionDialogLogic(props)
const { onOpenChange } = props
const [chrome, setChrome] = useState<AppDialogChrome | null>(null)
const [navigation, setNavigation] = useState<HTMLDivElement | null>(null)
const [footer, setFooter] = useState<HTMLDivElement | null>(null)
const surface = useMemo(
() => ({ setChrome, navigation, footer, close: () => onOpenChange(false) }),
[footer, navigation, onOpenChange],
)
// The user closed the dialog: the app's root dialog hears of it before the platform closes it.
const close = () => {
chrome?.onClose()
onOpenChange(false)
}

return (
<Modal
<AppDialogSurfaceModal
open={props.open}
onOpenChange={(open) => {
if (open) onOpenChange(true)
else close()
}}
closeDisabled={chrome?.closeDisabled ?? false}
title={chrome?.heading ?? state.title ?? t('appUi.unavailable')}
description={chrome?.description ?? props.hostDomains.join(', ')}
size="xl"
fixedHeight
height="tall"
navigation={chrome?.navigation ? <div ref={setNavigation} /> : undefined}
footer={
chrome?.footer ? (
<div ref={setFooter} className="contents" />
) : (
<button type="button" className={buttonClassName('secondary')} onClick={close}>
{t('appUi.hostTable.close')}
</button>
)
}
onOpenChange={props.onOpenChange}
title={state.title ?? t('appUi.unavailable')}
description={props.hostDomains.join(', ')}
>
{state.app && state.route ? (
<div className={chrome ? 'h-full' : 'h-full p-4'}>
<AppDialogSurfaceContext value={surface}>
<AppUiFrame
app={state.app}
slot="proxyHostTab"
hostId={props.hostId}
route={state.route}
onNavigate={handler.handleNavigate}
fill
/>
</AppDialogSurfaceContext>
</div>
<AppUiFrame
app={state.app}
slot="proxyHostTab"
hostId={props.hostId}
route={state.route}
onNavigate={handler.handleNavigate}
fill
/>
) : (
<output className="block p-4 text-sm text-muted">{t('appUi.unavailable')}</output>
<output className="block text-sm text-muted">{t('appUi.unavailable')}</output>
)}
</Modal>
</AppDialogSurfaceModal>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { TextInput } from '@rentnerkev/inputs'
import { CustomSelect } from '@rentnerkev/select'

import { buttonClassName } from '@/shared/Buttons/buttonStyles.ts'
import useTranslationStore from '@/shared/Language/Hooks/useTranslationStore.ts'
import type { AppUiDevPreviewSettingsProps } from '../Types/app-ui-dev-preview.types.ts'
import { APP_UI_DEV_BRIDGES } from '../validation.ts'

/** The installation the preview pretends to be; the settings take effect when applied. */
export default function AppUiDevPreviewSettings({
draft,
onDraftChange,
onApply,
}: AppUiDevPreviewSettingsProps) {
const { t } = useTranslationStore()

return (
<form
className="grid content-start gap-4 rounded-2xl border border-border bg-surface p-5 shadow-surface"
onSubmit={(event) => {
event.preventDefault()
onApply()
}}
>
<h2 className="font-display text-xl text-ink">{t('appUi.devPreview.settings')}</h2>
<CustomSelect
name="surface"
label={t('appUi.devPreview.surface')}
value={draft.surface}
options={[
{ value: 'page', label: t('appUi.devPreview.surfacePage') },
{ value: 'dialog', label: t('appUi.devPreview.surfaceDialog') },
]}
onValueChange={(surface: string) =>
onDraftChange({ ...draft, surface: surface === 'dialog' ? 'dialog' : 'page' })
}
/>
<CustomSelect
name="bridge"
label={t('appUi.devPreview.bridge')}
value={draft.bridge}
options={APP_UI_DEV_BRIDGES.map((version) => ({ value: version, label: version }))}
onValueChange={(bridge: string) =>
onDraftChange({
...draft,
bridge: APP_UI_DEV_BRIDGES.find((version) => version === bridge) ?? '1.3.0',
})
}
/>
<TextInput
name="name"
label={t('appUi.devPreview.name')}
value={draft.name}
maxLength={80}
autoComplete="off"
onValueChange={(name) => onDraftChange({ ...draft, name })}
/>
<TextInput
name="routes"
label={t('appUi.devPreview.routes')}
description={t('appUi.devPreview.routesHint')}
value={draft.routes}
autoComplete="off"
onValueChange={(routes) => onDraftChange({ ...draft, routes })}
/>
<TextInput
name="keys"
label={t('appUi.devPreview.keys')}
description={t('appUi.devPreview.keysHint')}
value={draft.keys}
autoComplete="off"
onValueChange={(keys) => onDraftChange({ ...draft, keys })}
/>
<TextInput
name="dialogs"
label={t('appUi.devPreview.dialogs')}
description={t('appUi.devPreview.dialogsHint')}
value={draft.dialogs}
autoComplete="off"
onValueChange={(dialogs) => onDraftChange({ ...draft, dialogs })}
/>
{draft.surface === 'dialog' ? (
<TextInput
name="host"
label={t('appUi.devPreview.host')}
description={t('appUi.devPreview.hostHint')}
value={draft.host ?? ''}
autoComplete="off"
onValueChange={(host) =>
onDraftChange({ ...draft, host: host.trim() || undefined })
}
/>
) : null}
<button type="submit" className={buttonClassName('primary')}>
{t('appUi.devPreview.apply')}
</button>
</form>
)
}
Loading