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
31 changes: 31 additions & 0 deletions apps/website/src/components/workshop/ExploreFinder.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<script setup lang="ts">
import { Search } from '@lucide/vue'

import type { Locale } from '@/i18n/translations'
import { translationsFor } from '@/i18n/translations'

const { locale = 'en' } = defineProps<{ locale?: Locale }>()
const { t } = translationsFor(locale)

const query = defineModel<string>({ required: true })
</script>

<template>
<label
class="relative mx-auto flex w-full max-w-2xl items-center"
data-testid="explore-finder"
>
<span class="sr-only">{{ t('workshop.explore.searchLabel') }}</span>
<Search
class="pointer-events-none absolute left-5 size-5 text-primary-warm-gray"
aria-hidden="true"
/>
<input
v-model="query"
type="search"
:placeholder="t('workshop.explore.searchPlaceholder')"
class="h-14 w-full rounded-2xl border border-transparency-white-t8 bg-hub-surface pr-6 pl-13 text-base text-primary-warm-white outline-none placeholder:text-primary-warm-gray focus-visible:ring-3 focus-visible:ring-primary-comfy-yellow/50"
data-testid="explore-search"
/>
</label>
</template>
51 changes: 51 additions & 0 deletions apps/website/src/components/workshop/ExploreHome.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import userEvent from '@testing-library/user-event'
import { render, screen, waitFor, within } from '@testing-library/vue'
import { describe, expect, it } from 'vitest'

import { workshopModels } from '@/config/workshop-browse-content'
import ExploreHome from './ExploreHome.vue'

const renderHome = () =>
render(ExploreHome, { props: { models: workshopModels, appsShown: true } })

const resultNames = () =>
within(screen.getByTestId('explore-results'))
.getAllByRole('link')
.map((link) => link.textContent.trim())

describe('Hub home', () => {
it('opens on the doors and the popular row', () => {
renderHome()

expect(screen.getByTestId('explore-doors')).toBeTruthy()
expect(resultNames().length).toBeGreaterThan(0)
})

it('answers a search with what matches it, and puts the doors away', async () => {
renderHome()

await userEvent
.setup()
.type(screen.getByTestId('explore-search'), 'upscale')

await waitFor(() =>
expect(screen.queryByTestId('explore-doors')).toBeNull()
)
const names = resultNames().join(' ').toLowerCase()
expect(names).toContain('upscale')
})

it('brings the doors back when the search is cleared', async () => {
renderHome()
const user = userEvent.setup()
const box = screen.getByTestId('explore-search')

await user.type(box, 'upscale')
await waitFor(() =>
expect(screen.queryByTestId('explore-doors')).toBeNull()
)
await user.clear(box)

expect(await screen.findByTestId('explore-doors')).toBeTruthy()
})
})
86 changes: 84 additions & 2 deletions apps/website/src/components/workshop/ExploreHome.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
<script setup lang="ts">
import { computed } from 'vue'
import { computed, ref } from 'vue'

import type {
AppWorkshopModel,
WorkflowWorkshopModel,
WorkshopModel
} from '@/config/models-catalogue'
import { catalogSearch, sortWorkshopModels } from '@/config/models-catalogue'
import { getRoutes } from '@/config/routes'
import type { Locale } from '@/i18n/translations'
import { translationsFor } from '@/i18n/translations'
import type { CatalogueApp } from '@/lib/workshop/catalogue-apps'
import { ac } from '@/lib/workshop/catalogue-apps'
import { doorArt } from '@/lib/workshop/explore-art'
import type { ExploreCount, ExploreEntry } from '@/lib/workshop/explore-search'
import { exploreRow, searchExplore } from '@/lib/workshop/explore-search'
import { isWorkshopModelShown } from '@/scripts/workshop-model-flags'
import ExploreDoors from './ExploreDoors.vue'
import ExploreFinder from './ExploreFinder.vue'
import ExploreResults from './ExploreResults.vue'

const RESULTS = 12

const {
models,
Expand All @@ -22,6 +31,11 @@ const {
appsShown: boolean
locale?: Locale
}>()
const { t } = translationsFor(locale)
const routes = getRoutes(locale)

const query = ref('')
const needle = computed(() => query.value.trim())

const shown = computed(() => models.filter(isWorkshopModelShown))
const routerModels = computed(() =>
Expand Down Expand Up @@ -65,10 +79,78 @@ const counts = computed(() => ({
workflows: workflows.value.length,
apps: apps.value.length
}))

const matches = computed(() =>
searchExplore(
{
apps: apps.value,
workflows: workflows.value,
models: routerModels.value
},
needle.value
)
)

const popular = computed<ExploreEntry[]>(() => [
...apps.value.map((app) => ({ kind: 'app' as const, app })),
...sortWorkshopModels([...workflows.value, ...routerModels.value], 'popular')
.slice(0, RESULTS - apps.value.length)
.map((model) => ({
kind: model.workflowId ? ('workflow' as const) : ('model' as const),
model
}))
])

const entries = computed(() =>
needle.value ? exploreRow(matches.value, RESULTS) : popular.value
)

const kindCounts = computed<ExploreCount[]>(() => {
if (!needle.value) return []
const search = catalogSearch({ query: needle.value })
return [
{
kind: 'models' as const,
count: matches.value.models.length,
href: routes.workshop + search
},
{
kind: 'workflows' as const,
count: matches.value.workflows.length,
href: routes.hubWorkflows + search
},
{
kind: 'apps' as const,
count: matches.value.apps.length,
href: routes.hubApps
}
].filter((entry) => entry.count > 0)
})

const resultsTitle = computed(() =>
needle.value
? t('workshop.explore.resultsFor', { query: needle.value })
: t('workshop.explore.popularTitle')
)

function clear() {
query.value = ''
}
</script>

<template>
<div class="mt-2 flex flex-col gap-14" data-testid="explore-home">
<ExploreDoors :counts :art :locale />
<ExploreFinder v-model="query" :locale />

<ExploreDoors v-if="!needle" :counts :art :locale />

<ExploreResults
v-if="needle || entries.length"
:title="resultsTitle"
:entries
:counts="kindCounts"
:locale
@clear="clear"
/>
</div>
</template>
59 changes: 59 additions & 0 deletions apps/website/src/components/workshop/ExploreKindTag.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<script setup lang="ts">
import { cn } from '@comfyorg/tailwind-utils'

import Badge from '@/components/ui/badge/Badge.vue'
import IconApps from '@/components/hub/IconApps.vue'
import IconModel from '@/components/hub/IconModel.vue'
import IconWorkflow from '@/components/hub/IconWorkflow.vue'
import type { Locale, TranslationKey } from '@/i18n/translations'
import { translationsFor } from '@/i18n/translations'
import type { ExploreKind } from '@/lib/workshop/explore-search'

const { kind, locale = 'en' } = defineProps<{
kind: ExploreKind
locale?: Locale
}>()
const { t } = translationsFor(locale)

// Each kind's door colour, let through over the cover like the maker mark.
const KINDS = {
app: {
label: 'workshop.explore.kindApp',
icon: IconApps,
surface: 'bg-cobalt-800/70'
},
workflow: {
label: 'workshop.explore.workflowPill',
icon: IconWorkflow,
surface: 'bg-primary-comfy-plum/70'
},
model: {
label: 'workshop.explore.kindModel',
icon: IconModel,
surface: 'bg-illustration-forest/70'
}
} as const satisfies Record<
ExploreKind,
{ label: TranslationKey; icon: typeof IconApps; surface: string }
>
</script>

<template>
<Badge
:class="
cn(
'pointer-events-none absolute top-4 left-4 z-10 size-7 justify-center rounded-lg p-0 text-primary-warm-white backdrop-blur-md',
KINDS[kind].surface
)
"
data-testid="explore-kind"
:data-kind="kind"
>
<component
:is="KINDS[kind].icon"
class="size-3.5 shrink-0"
aria-hidden="true"
/>
<span class="sr-only">{{ t(KINDS[kind].label) }}</span>
</Badge>
</template>
116 changes: 116 additions & 0 deletions apps/website/src/components/workshop/ExploreResultCard.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { render, screen, within } from '@testing-library/vue'
import { describe, expect, it } from 'vitest'

import ExploreResultCard from './ExploreResultCard.vue'

const still = {
name: 'Relight',
thumbnail: { url: '/still.jpg', kind: 'image' }
} as const

describe('ExploreResultCard', () => {
it.for([
{ art: 'a still', model: still, images: ['/still.jpg'] },
{ art: 'nothing', model: undefined, images: [] }
] as const)(
'reads as its name and its pills with $art',
({ model, images }) => {
render(ExploreResultCard, {
props: {
href: '/hub/workflows/relight/',
kind: 'workflow',
name: 'Relight',
pills: ['Edit images'],
model
}
})

expect(screen.getByRole('link')).toHaveTextContent(
/^\s*Workflow\s*Relight\s*Edit images\s*$/
)
expect(
screen.queryAllByAltText('').map((img) => img.getAttribute('src'))
).toEqual(images)
}
)

it('marks its kind top left and its maker top right over the artwork', () => {
render(ExploreResultCard, {
props: {
href: '/hub/models/beeble/',
kind: 'model',
name: 'Beeble SwitchX',
model: still,
source: 'Beeble',
logo: '/logos/beeble.svg',
pills: ['Edit images']
}
})

const artwork = within(screen.getByTestId('explore-artwork'))
const meta = within(screen.getByTestId('explore-meta'))
expect(artwork.getByTestId('explore-kind')).toHaveTextContent('Model')
expect(artwork.getByTestId('explore-kind')).toHaveClass('top-4', 'left-4')
expect(artwork.getByTestId('explore-source')).toHaveTextContent('Beeble')
expect(artwork.getByTestId('explore-source')).toHaveClass(
'top-4',
'right-4'
)
expect(artwork.getByTestId('model-card-provider-logo')).toHaveStyle({
maskImage: 'url(/logos/beeble.svg)'
})
expect(
within(meta.getByTestId('explore-pills'))
.getAllByText(/./)
.map((pill) => pill.textContent.trim())
).toEqual(['Edit images'])
expect(screen.getByRole('link')).toHaveTextContent(
/^\s*Model\s*Beeble\s*Beeble SwitchX\s*Edit images\s*$/
)
})

it('names the maker over the artwork when it has no logo', () => {
render(ExploreResultCard, {
props: { kind: 'workflow', name: 'Relight', source: 'Nobody', pills: [] }
})

expect(screen.getByTestId('explore-source')).toHaveTextContent('Nobody')
expect(screen.queryByTestId('model-card-provider-logo')).toBeNull()
})

it('shows the kind as an icon and keeps its name for screen readers', () => {
render(ExploreResultCard, {
props: { kind: 'model', name: 'Beeble SwitchX', model: still, pills: [] }
})

expect(screen.getByText('Model')).toHaveClass('sr-only')
})

it.for([
{
href: '/hub/apps/cinematic-studio/',
newTab: true,
links: 1,
target: '_blank'
},
{
href: '/hub/workflows/relight/',
newTab: false,
links: 1,
target: undefined
},
{ href: undefined, newTab: true, links: 0, target: undefined }
])(
'opens an app in a tab of its own, and nothing for one still coming ($href)',
({ href, newTab, links, target }) => {
render(ExploreResultCard, {
props: { href, newTab, kind: 'app', name: 'Relight', pills: [] }
})

expect(screen.queryAllByRole('link')).toHaveLength(links)
expect(
screen.getByTestId('explore-result').getAttribute('target') ?? undefined
).toBe(target)
}
)
})
Loading
Loading