feat(courses): add type, search, and pricing filters to org landing page

- Add Types section to the Filter sidebar with all 4 course types
- Add full-text search input centered in the hero (title + description)
- Add Pricing section (Free / Paid) based on course cost
- Compact hero prop across all 10 themes to halve vertical padding
- Children snippet support in all hero themes for the search input
- All filters are URL-driven (?types=, ?search=, ?tags=, ?pricing=)
- Full-stack: validation schema, DB queries, service, API route, server load, UI
This commit is contained in:
Rotimi Best
2026-07-01 10:36:53 +01:00
parent 8d2f2a6d2d
commit 78a2b85ad3
27 changed files with 464 additions and 97 deletions
+41 -2
View File
@@ -11,7 +11,7 @@ import {
TNewCourseSection,
TProfile
} from '@db/types';
import { and, count, desc, eq, ilike, inArray, isNotNull, isNull, or, sql } from 'drizzle-orm';
import { and, count, desc, eq, gt, ilike, inArray, isNotNull, isNull, or, sql } from 'drizzle-orm';
import { ROLE } from '@cio/utils/constants';
import { db, type DbOrTxClient } from '@db/drizzle';
@@ -59,6 +59,9 @@ export interface TStudentCourse extends TBaseCourse {
export const getPublishedCoursesBySiteName = async (
siteName: string,
courseIds?: string[],
courseTypes?: string[],
search?: string,
pricing?: 'free' | 'paid',
limit?: number,
offset?: number
): Promise<TBaseCourse[]> => {
@@ -77,6 +80,21 @@ export const getPublishedCoursesBySiteName = async (
conditions.push(inArray(schema.course.id, courseIds));
}
if (courseTypes && courseTypes.length > 0) {
conditions.push(inArray(schema.course.type, courseTypes as (typeof schema.courseType.enumValues)[number][]));
}
if (search) {
const pattern = `%${search}%`;
conditions.push(or(ilike(schema.course.title, pattern), ilike(schema.course.description, pattern))!);
}
if (pricing === 'free') {
conditions.push(eq(schema.course.cost, 0));
} else if (pricing === 'paid') {
conditions.push(gt(schema.course.cost, 0));
}
const exerciseCountSql = sql<number>`(
SELECT COUNT(*)::bigint
FROM ${schema.exercise} as ex
@@ -127,7 +145,13 @@ export const getPublishedCoursesBySiteName = async (
}
};
export const countPublishedCoursesBySiteName = async (siteName: string, courseIds?: string[]): Promise<number> => {
export const countPublishedCoursesBySiteName = async (
siteName: string,
courseIds?: string[],
courseTypes?: string[],
search?: string,
pricing?: 'free' | 'paid'
): Promise<number> => {
try {
if (courseIds && courseIds.length === 0) {
return 0;
@@ -143,6 +167,21 @@ export const countPublishedCoursesBySiteName = async (siteName: string, courseId
conditions.push(inArray(schema.course.id, courseIds));
}
if (courseTypes && courseTypes.length > 0) {
conditions.push(inArray(schema.course.type, courseTypes as (typeof schema.courseType.enumValues)[number][]));
}
if (search) {
const pattern = `%${search}%`;
conditions.push(or(ilike(schema.course.title, pattern), ilike(schema.course.description, pattern))!);
}
if (pricing === 'free') {
conditions.push(eq(schema.course.cost, 0));
} else if (pricing === 'paid') {
conditions.push(gt(schema.course.cost, 0));
}
const [result] = await db
.select({
total: count(schema.course.id)
@@ -1,5 +1,6 @@
<script lang="ts">
import type { OrgLandingPageProps } from '../types';
import type { Snippet } from 'svelte';
import SecondaryActionButton from '../secondary-action-button.svelte';
import { Button } from '../../../base/button';
import EditableLandingSection from '../editable-section.svelte';
@@ -7,16 +8,25 @@
interface Props {
hero: OrgLandingPageProps['hero'];
showActions?: boolean;
compact?: boolean;
children?: Snippet;
}
let { hero, showActions = true }: Props = $props();
let { hero, showActions = true, compact = false, children }: Props = $props();
</script>
<EditableLandingSection sectionKey="hero">
<section class="ui:py-10 ui:px-6 ui:max-w-7xl ui:mx-auto ui:grid ui:lg:grid-cols-2 ui:gap-16 ui:items-center">
<section
class="{compact
? 'ui:py-5'
: 'ui:py-10'} ui:px-6 ui:max-w-7xl ui:mx-auto ui:grid ui:lg:grid-cols-2 ui:gap-16 ui:items-center"
>
<div>
<h1 class="ui:text-5xl ui:lg:text-7xl ui:font-black ui:leading-[1.1] ui:tracking-tighter">{hero.heading}</h1>
<p class="ui:text-xl ui:text-[var(--landing-fg-muted)] ui:mb-10 ui:leading-relaxed">{hero.subheading}</p>
{#if children}
<div class="ui:mt-6">{@render children()}</div>
{/if}
{#if showActions}
<div class="ui:flex ui:flex-wrap ui:gap-4">
<Button
@@ -1,5 +1,6 @@
<script lang="ts">
import type { OrgLandingPageProps } from '../types';
import type { Snippet } from 'svelte';
import SecondaryActionButton from '../secondary-action-button.svelte';
import { Button } from '../../../base/button';
import { BlurIn } from '../../animation/blurin';
@@ -9,14 +10,18 @@
interface Props {
hero: OrgLandingPageProps['hero'];
showActions?: boolean;
compact?: boolean;
children?: Snippet;
}
let { hero, showActions = true }: Props = $props();
let { hero, showActions = true, compact = false, children }: Props = $props();
</script>
<EditableLandingSection sectionKey="hero">
<section
class="ui:relative ui:bg-[var(--landing-fg)] ui:text-[var(--landing-bg)] ui:overflow-hidden ui:py-24 ui:sm:py-32 ui:px-6 ui:lg:px-8"
class="ui:relative ui:bg-[var(--landing-fg)] ui:text-[var(--landing-bg)] ui:overflow-hidden {compact
? 'ui:py-12 ui:sm:py-16'
: 'ui:py-24 ui:sm:py-32'} ui:px-6 ui:lg:px-8"
>
{#if hero.image}
<div class="ui:absolute ui:inset-0 ui:opacity-10">
@@ -31,6 +36,9 @@
{hero.heading}
</BlurIn>
<p class="ui:text-lg ui:sm:text-xl ui:text-[var(--landing-bg)]/80 ui:mb-10">{hero.subheading}</p>
{#if children}
<div class="ui:flex ui:justify-center ui:w-full ui:mb-8">{@render children()}</div>
{/if}
{#if showActions}
<div class="ui:flex ui:flex-col ui:sm:flex-row ui:justify-center ui:gap-4">
<Button
@@ -10,9 +10,11 @@
hero: OrgLandingPageProps['hero'];
navigation: Snippet;
showActions?: boolean;
compact?: boolean;
children?: Snippet;
}
let { orgName, hero, navigation, showActions = true }: Props = $props();
let { orgName, hero, navigation, showActions = true, compact = false, children }: Props = $props();
const stats = $derived(hero.stats ?? []);
</script>
@@ -20,7 +22,9 @@
{@render navigation()}
<EditableLandingSection sectionKey="hero">
<section class="ui:px-6 ui:pt-12 ui:pb-24 ui:md:pt-16 ui:md:pb-28">
<section
class="ui:px-6 {compact ? 'ui:pt-6 ui:pb-12 ui:md:pt-8 ui:md:pb-14' : 'ui:pt-12 ui:pb-24 ui:md:pt-16 ui:md:pb-28'}"
>
<div class="ui:max-w-[1120px] ui:mx-auto">
<div class="ui:flex ui:items-center ui:gap-4 ui:pb-5 ui:mb-10 ui:border-b ui:border-[var(--landing-border)]">
<span class="ui:text-[11px] ui:font-semibold ui:tracking-[0.2em] ui:uppercase ui:text-[var(--landing-fg)]">
@@ -48,6 +52,9 @@
{hero.subheading}
</p>
{#if children}
<div class="ui:mt-6">{@render children()}</div>
{/if}
{#if showActions}
<div class="ui:flex ui:flex-wrap ui:items-center ui:gap-3">
<Button
@@ -12,9 +12,11 @@
labels?: OrgLandingPageProps['labels'];
navigation: Snippet;
showActions?: boolean;
compact?: boolean;
children?: Snippet;
}
let { hero, courses = [], labels, navigation, showActions = true }: Props = $props();
let { hero, courses = [], labels, navigation, showActions = true, compact = false, children }: Props = $props();
const featured = $derived(courses[0]);
const featuredTypeMeta = $derived(featured ? getCourseTypeLandingMeta(featured) : undefined);
@@ -38,7 +40,11 @@
{@render navigation()}
<EditableLandingSection sectionKey="hero">
<section class="ui:px-6 ui:md:px-8 ui:pt-16 ui:md:pt-20 ui:pb-12 ui:bg-[var(--landing-bg)]">
<section
class="ui:px-6 ui:md:px-8 {compact
? 'ui:pt-8 ui:md:pt-10 ui:pb-6'
: 'ui:pt-16 ui:md:pt-20 ui:pb-12'} ui:bg-[var(--landing-bg)]"
>
<div class="ui:max-w-[1240px] ui:mx-auto">
<div
class="ui:grid ui:grid-cols-1 ui:gap-12 ui:lg:gap-14 ui:items-start {featured
@@ -72,6 +78,9 @@
{hero.subheading}
</p>
{#if children}
<div class="ui:mt-6 {featured ? '' : 'ui:flex ui:justify-center'}">{@render children()}</div>
{/if}
{#if showActions}
<div class="ui:flex ui:flex-wrap ui:items-center ui:gap-2.5 {featured ? '' : 'ui:justify-center'}">
<Button
@@ -11,9 +11,11 @@
hero: OrgLandingPageProps['hero'];
navigation: Snippet;
showActions?: boolean;
compact?: boolean;
children?: Snippet;
}
let { hero, navigation, showActions = true }: Props = $props();
let { hero, navigation, showActions = true, compact = false, children }: Props = $props();
const heroGradientBackground = `
radial-gradient(
@@ -32,7 +34,7 @@
<EditableLandingSection sectionKey="hero">
<section
class="ui:relative ui:overflow-hidden ui:px-4 ui:pt-4 ui:pb-16 ui:md:pb-24"
class="ui:relative ui:overflow-hidden ui:px-4 ui:pt-4 {compact ? 'ui:pb-8 ui:md:pb-12' : 'ui:pb-16 ui:md:pb-24'}"
style={`background: ${heroGradientBackground};`}
>
<DotPattern class="ui:opacity-[0.08]" />
@@ -40,7 +42,7 @@
{@render navigation()}
</div>
<div class="ui:relative ui:py-20 ui:text-center ui:max-w-4xl ui:mx-auto">
<div class="ui:relative {compact ? 'ui:py-10' : 'ui:py-20'} ui:text-center ui:max-w-4xl ui:mx-auto">
<h1 class="ui:text-5xl ui:md:text-6xl ui:font-semibold ui:tracking-tight ui:mb-6">{hero.heading}</h1>
<ShinnyText
shimmerWidth={120}
@@ -48,6 +50,9 @@
>
{hero.subheading}
</ShinnyText>
{#if children}
<div class="ui:flex ui:justify-center ui:w-full ui:mb-8">{@render children()}</div>
{/if}
{#if showActions}
<div class="ui:flex ui:items-center ui:justify-center ui:gap-4">
<Button
@@ -9,18 +9,24 @@
hero: OrgLandingPageProps['hero'];
navigation: Snippet;
showActions?: boolean;
compact?: boolean;
children?: Snippet;
}
let { hero, navigation, showActions = true }: Props = $props();
let { hero, navigation, showActions = true, compact = false, children }: Props = $props();
</script>
<EditableLandingSection sectionKey="hero">
<section class="ui:relative ui:px-6 ui:pt-4 ui:pb-20 ui:md:pb-24">
<section class="ui:relative ui:px-6 ui:pt-4 {compact ? 'ui:pb-10 ui:md:pb-12' : 'ui:pb-20 ui:md:pb-24'}">
<div class="ui:relative ui:max-w-[1180px] ui:mx-auto ui:sticky ui:top-4 ui:z-50">
{@render navigation()}
</div>
<div class="ui:relative ui:max-w-[1180px] ui:mx-auto ui:pt-16 ui:md:pt-20 ui:text-center">
<div
class="ui:relative ui:max-w-[1180px] ui:mx-auto {compact
? 'ui:pt-8 ui:md:pt-10'
: 'ui:pt-16 ui:md:pt-20'} ui:text-center"
>
<h1
class="ui:text-4xl ui:md:text-5xl ui:lg:text-[56px] ui:font-bold ui:tracking-tight ui:leading-[1.05] ui:max-w-3xl ui:mx-auto ui:mb-5"
>
@@ -33,6 +39,9 @@
{hero.subheading}
</p>
{#if children}
<div class="ui:flex ui:justify-center ui:w-full ui:mb-8">{@render children()}</div>
{/if}
{#if showActions}
<div class="ui:flex ui:items-center ui:justify-center ui:gap-2.5">
<Button
@@ -10,9 +10,11 @@
courses: OrgLandingPageProps['courses'];
navigation: Snippet;
showActions?: boolean;
compact?: boolean;
children?: Snippet;
}
let { hero, courses = [], navigation, showActions = true }: Props = $props();
let { hero, courses = [], navigation, showActions = true, compact = false, children }: Props = $props();
const coursesCount = $derived(courses.length);
@@ -29,7 +31,11 @@
{@render navigation()}
<EditableLandingSection sectionKey="hero">
<section class="ui:relative ui:overflow-hidden ui:px-6 ui:pt-20 ui:pb-20 ui:md:pt-24 ui:md:pb-24">
<section
class="ui:relative ui:overflow-hidden ui:px-6 {compact
? 'ui:pt-10 ui:pb-10 ui:md:pt-12 ui:md:pb-12'
: 'ui:pt-20 ui:pb-20 ui:md:pt-24 ui:md:pb-24'}"
>
<div
class="ui:pointer-events-none ui:absolute ui:-top-32 ui:-left-24 ui:h-[520px] ui:w-[520px] ui:rounded-full ui:opacity-60 ui:blur-3xl"
style="background: radial-gradient(circle, color-mix(in oklab, var(--landing-accent) 35%, transparent) 0%, transparent 70%);"
@@ -59,6 +65,9 @@
{hero.subheading}
</p>
{#if children}
<div class="ui:mt-6">{@render children()}</div>
{/if}
{#if showActions}
<div class="ui:flex ui:flex-wrap ui:items-center ui:gap-2">
<Button
@@ -9,14 +9,18 @@
hero: OrgLandingPageProps['hero'];
navigation: Snippet;
showActions?: boolean;
compact?: boolean;
children?: Snippet;
}
let { hero, navigation, showActions = true }: Props = $props();
let { hero, navigation, showActions = true, compact = false, children }: Props = $props();
</script>
<EditableLandingSection sectionKey="hero">
<section
class="ui:relative ui:bg-[var(--landing-accent)] ui:text-[var(--landing-accent-fg)] ui:overflow-hidden ui:px-6 ui:pt-2 ui:pb-20"
class="ui:relative ui:bg-[var(--landing-accent)] ui:text-[var(--landing-accent-fg)] ui:overflow-hidden ui:px-6 ui:pt-2 {compact
? 'ui:pb-10'
: 'ui:pb-20'}"
>
<!-- subtle grid overlay -->
<div
@@ -30,7 +34,9 @@
</div>
<div
class="ui:relative ui:max-w-[1280px] ui:mx-auto ui:py-16 ui:lg:py-24 ui:grid ui:lg:grid-cols-2 ui:gap-12 ui:items-center"
class="ui:relative ui:max-w-[1280px] ui:mx-auto {compact
? 'ui:py-8 ui:lg:py-12'
: 'ui:py-16 ui:lg:py-24'} ui:grid ui:lg:grid-cols-2 ui:gap-12 ui:items-center"
>
<div>
<p
@@ -46,6 +52,9 @@
>
{hero.subheading}
</p>
{#if children}
<div class="ui:mt-6">{@render children()}</div>
{/if}
{#if showActions}
<div class="ui:flex ui:flex-wrap ui:items-center ui:gap-3">
<Button
@@ -10,9 +10,11 @@
courses: OrgLandingPageProps['courses'];
navigation: Snippet;
showActions?: boolean;
compact?: boolean;
children?: Snippet;
}
let { orgName = '', hero, courses = [], navigation, showActions = true }: Props = $props();
let { orgName = '', hero, courses = [], navigation, showActions = true, compact = false, children }: Props = $props();
const coursesCount = $derived(courses.length);
const learnersCount = $derived(courses.reduce((sum, course) => sum + (course.totalStudents ?? 0), 0));
@@ -63,7 +65,9 @@
<EditableLandingSection sectionKey="hero">
<section
class="ui:relative ui:overflow-hidden ui:px-6 ui:pt-16 ui:pb-16 ui:md:pt-20 ui:md:pb-20 ui:bg-[var(--landing-bg)]"
class="ui:relative ui:overflow-hidden ui:px-6 {compact
? 'ui:pt-8 ui:pb-8 ui:md:pt-10 ui:md:pb-10'
: 'ui:pt-16 ui:pb-16 ui:md:pt-20 ui:md:pb-20'} ui:bg-[var(--landing-bg)]"
>
<div
class="ui:pointer-events-none ui:absolute ui:inset-x-0 ui:-top-32 ui:h-[680px] ui:opacity-90"
@@ -118,6 +122,9 @@
{hero.subheading}
</p>
{#if children}
<div class="ui:flex ui:justify-center ui:w-full ui:mb-8">{@render children()}</div>
{/if}
{#if coursesCount > 0}
<span
class="ui:inline-flex ui:items-center ui:gap-3 ui:px-4 ui:py-2 ui:rounded-full ui:font-mono ui:text-[13px] ui:text-[var(--landing-fg-muted)]"
@@ -10,16 +10,20 @@
labels?: OrgLandingPageProps['labels'];
navigation: Snippet;
showActions?: boolean;
compact?: boolean;
children?: Snippet;
}
let { hero, labels, navigation, showActions = true }: Props = $props();
let { hero, labels, navigation, showActions = true, compact = false, children }: Props = $props();
</script>
{@render navigation()}
<EditableLandingSection sectionKey="hero">
<section
class="ui:relative ui:px-6 ui:md:px-8 ui:pt-20 ui:md:pt-24 ui:pb-20 ui:md:pb-24 ui:bg-[var(--landing-bg)] ui:text-center"
class="ui:relative ui:px-6 ui:md:px-8 {compact
? 'ui:pt-10 ui:md:pt-12 ui:pb-10 ui:md:pb-12'
: 'ui:pt-20 ui:md:pt-24 ui:pb-20 ui:md:pb-24'} ui:bg-[var(--landing-bg)] ui:text-center"
>
<div class="ui:max-w-[1320px] ui:mx-auto">
<h1
@@ -36,6 +40,9 @@
{hero.subheading}
</p>
{#if children}
<div class="ui:flex ui:justify-center ui:w-full ui:mb-8">{@render children()}</div>
{/if}
{#if showActions}
<div class="ui:inline-flex ui:flex-wrap ui:justify-center ui:items-center ui:gap-3">
<Button
File diff suppressed because one or more lines are too long
@@ -19,6 +19,9 @@ export type TGetOrganizations = z.infer<typeof ZGetOrganizations>;
export const ZGetCoursesBySiteName = z.object({
siteName: z.string().min(1),
tags: z.string().optional(),
types: z.string().optional(),
search: z.string().trim().optional(),
pricing: z.enum(['free', 'paid']).optional(),
page: z.coerce.number().int().min(1).optional(),
limit: z.coerce.number().int().min(1).max(100).optional()
});