8000 Add managed series with post and podcast kinds by kiran-brahma · Pull Request #3 · kiran-brahma/microfeed · GitHub
[go: up one dir, main page]

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
2 changes: 2 additions & 0 deletions manage-cli/lib/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export const SNAPSHOT_TABLES = {
"theme_state",
"categories",
"item_categories",
"series",
"item_series",
],
ephemeral: [
"item_create_idempotency",
Expand Down
23 changes: 23 additions & 0 deletions migrations/0018_series.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- Personal-site series: a managed list of series assignable to items.
-- Series are typed so posts and podcasts keep separate series. An item can
-- belong to at most one series, with an optional series number.

CREATE TABLE IF NOT EXISTS series (
id TEXT PRIMARY KEY,
kind TEXT NOT NULL CHECK (kind IN ('post', 'podcast')),
name TEXT NOT NULL,
slug TEXT NOT NULL COLLATE NOCASE,
description TEXT,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE (kind, slug)
);

CREATE TABLE IF NOT EXISTS item_series (
item_id TEXT PRIMARY KEY,
series_id TEXT NOT NULL,
series_number INTEGER
);

CREATE INDEX IF NOT EXISTS item_series_series_id
ON item_series (series_id);
2 changes: 2 additions & 0 deletions src/components/admin/AdminSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
PlusIcon,
SettingsIcon,
TagsIcon,
LayersIcon,
} from "lucide-react";

import {
Expand Down Expand Up @@ -38,6 +39,7 @@ const navigationIcons: Record<AdminNavItemId, typeof HomeIcon> = {
[NAV_ITEMS.PAGES]: FileTextIcon,
[NAV_ITEMS.SITE_FILES]: FileCode2Icon,
[NAV_ITEMS.CATEGORIES]: TagsIcon,
[NAV_ITEMS.SERIES]: LayersIcon,
[NAV_ITEMS.API]: Code2Icon,
[NAV_ITEMS.SETTINGS]: SettingsIcon,
};
Expand Down
108 changes: 108 additions & 0 deletions src/components/admin/items/EditItemApp/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
ONBOARDING_TYPES,
STATUSES,
ITEM_STATUSES_DICT,
ENCLOSURE_CATEGORIES,
} from "@/shared/Constants";
import {AdminSideQuickLinks, SideQuickLink} from "@/components/admin/shared/AdminSideQuickLinks";
import AdminRichEditor from "@/components/admin/shared/AdminRichEditor";
Expand Down Expand Up @@ -53,6 +54,11 @@ import {queueReplacedImageUrl} from "@/client/ImageUploadUtils";
import AdminSaveAction from "@/components/admin/shared/AdminSaveAction";
import {cn} from "@/lib/utils";
import {MAX_CATEGORIES_PER_ITEM, type CategoryRecord} from "@/shared/Categories";
import {
SERIES_KINDS,
type SeriesKind,
type SeriesRecord,
} from "@/shared/Series";

const SUBMIT_STATUS__START = 1;

Expand All @@ -66,6 +72,28 @@ function itemCategoryIds(item: Record<string, unknown>): string[] {
).filter((id): id is string => typeof id === "string" && id.length > 0);
}

function itemKind(item: Record<string, unknown>): SeriesKind {
const category = (item.mediaFile as {category?: unknown})?.category;
return category === ENCLOSURE_CATEGORIES.AUDIO
? SERIES_KINDS.PODCAST
: SERIES_KINDS.POST;
}

function itemSeriesId(item: Record<string, unknown>): string | null {
const series = item.series;
if (typeof series === "string") return series;
const id = (series as {id?: unknown})?.id;
return typeof id === "string" && id.length > 0 ? id : null;
}

function itemSeriesNumber(item: Record<string, unknown>): string {
const series = item.series;
const number = (series as {series_number?: unknown})?.series_number;
return number === null || number === undefined || number === ""
? ""
: String(number);
}

function initItem(itemId: string) {
return ({
status: STATUSES.UNPUBLISHED,
Expand All @@ -83,6 +111,7 @@ interface Props {
feedContent: FeedContent;
itemId?: string;
onboardingResult: OnboardingResult;
series: SeriesRecord[];
}

interface ItemSnapshot {
Expand Down Expand Up @@ -468,6 +497,85 @@ export default class EditItemApp extends React.Component<Props, any> {
</div>
)}
</div>
<div className="rounded-[14px] border bg-card p-5 text-card-foreground shadow-xs">
<div className="mb-2 text-sm font-semibold text-foreground">Series</div>
<p className="mb-4 text-xs text-muted-foreground">
Group this {itemKind(item)} into a series. Posts and podcasts
keep separate series.
</p>
{(() => {
const kind = itemKind(item);
const kindSeries = (this.props.series ?? []).filter(
(entry) => entry.kind === kind,
);
const selectedId = itemSeriesId(item);
return (
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
<div className="grid gap-2">
<label className="text-sm font-medium" htmlFor="item-series">
Series
</label>
<select
className="rounded-[10px] border bg-card px-3 py-2 text-sm"
id="item-series"
=> {
const value = event.target.value;
const current = item.series as Record<string, unknown> | null;
this.onUpdateItemMeta({
series: value
? {
...(current && typeof current === "object"
? current
: {}),
id: value,
}
: null,
});
}}
value={selectedId ?? ""}
>
<option value="">No series</option>
{kindSeries.map((entry) => (
<option key={entry.id} value={entry.id}>
{entry.name}
</option>
))}
</select>
{kindSeries.length === 0 && (
<p className="text-xs text-muted-foreground">
No {kind} series yet. Add one in the Series page first.
</p>
)}
</div>
<div className="grid gap-2">
<label className="text-sm font-medium" htmlFor="item-series-number">
Series number
</label>
<input
className="rounded-[10px] border bg-card px-3 py-2 text-sm"
id="item-series-number"
min="1"
=> {
const value = event.target.value;
const current = item.series as Record<string, unknown> | null;
this.onUpdateItemMeta({
series: {
...(current && typeof current === "object"
? current
: {}),
series_number: value === "" ? null : Number(value),
},
});
}}
placeholder="Optional"
type="number"
value={itemSeriesNumber(item)}
/>
</div>
</div>
);
})()}
</div>
<div className="rounded-[14px] border bg-card p-5 text-card-foreground shadow-xs">
<details>
<summary className="m-page-summary">Podcast-specific fields</summary>
Expand Down
Loading
0