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
3 changes: 3 additions & 0 deletions drizzle/0046_store_listing_team.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE "store_listings" ADD COLUMN IF NOT EXISTS "team" jsonb DEFAULT '[]'::jsonb NOT NULL;
--> statement-breakpoint
CREATE INDEX IF NOT EXISTS "store_listings_team_idx" ON "store_listings" USING gin ("team" jsonb_path_ops);
7 changes: 7 additions & 0 deletions drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@
"when": 1779600000000,
"tag": "0045_store_listing_transfers",
"breakpoints": true
},
{
"idx": 46,
"version": "7",
"when": 1779700000000,
"tag": "0046_store_listing_team",
"breakpoints": true
}
]
}
16 changes: 16 additions & 0 deletions lexicons/fyi/atstore/directory/getListing.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@
"uri": { "type": "string", "maxLength": 2048 }
}
},
"listingTeamMemberRow": {
"type": "object",
"required": ["did"],
"properties": {
"did": { "type": "string", "format": "did" },
"role": { "type": "string", "maxLength": 640 }
}
},
"listingDetailResponse": {
"type": "object",
"required": [
Expand Down Expand Up @@ -147,6 +155,14 @@
"type": "ref",
"ref": "#listingLinkRow"
}
},
"team": {
"type": "array",
"description": "People behind the listing, in display order.",
"items": {
"type": "ref",
"ref": "#listingTeamMemberRow"
}
}
}
},
Expand Down
26 changes: 26 additions & 0 deletions lexicons/fyi/atstore/listing/detail.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,36 @@
"type": "ref",
"ref": "#link"
}
},
"team": {
"type": "array",
"maxLength": 24,
"description": "People behind the listing (developers, designers, and anyone else the owner wants to credit), in display order.",
"items": {
"type": "ref",
"ref": "#teamMember"
}
}
}
}
},
"teamMember": {
"type": "object",
"required": ["did"],
"properties": {
"did": {
"type": "string",
"format": "did",
"description": "The team member's account."
},
"role": {
"type": "string",
"maxLength": 640,
"maxGraphemes": 64,
"description": "Free-form role on the team, e.g. 'Developer' or 'Design'."
}
}
},
"link": {
"type": "object",
"required": ["type", "url"],
Expand Down
193 changes: 192 additions & 1 deletion src/components/product-listing-form.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type {
ListingLink,
ListingLinkType,
ListingTeamMember,
} from "#/lib/atproto/listing-record";
import type { ReactNode } from "react";
import type { DropTarget } from "react-aria-components";

import * as stylex from "@stylexjs/stylex";
import { useSuspenseQuery } from "@tanstack/react-query";
import { useQuery, useSuspenseQuery } from "@tanstack/react-query";
import { ImageCropperDialog } from "#/components/image-cropper-dialog";
import {
FieldHelp,
Expand All @@ -28,6 +29,9 @@ import {
import {
LISTING_LINK_MAX_COUNT,
LISTING_LINK_TYPES,
LISTING_TEAM_MAX_COUNT,
LISTING_TEAM_ROLE_MAX_LENGTH,
LISTING_TEAM_ROLE_SUGGESTIONS,
} from "#/lib/atproto/listing-record";
import { slugifyDirectoryListingName } from "#/lib/directory-listing-slugs";
import {
Expand Down Expand Up @@ -111,6 +115,55 @@ type LinkRow = {
label: string;
};

type TeamRow = {
/** Local-only id so React can track the row across removals. */
id: string;
/** Handle as typed (or a DID until the saved member's handle loads). */
actor: string;
role: string;
};

/** What the form submits per team row; the server resolves handles to DIDs. */
type ProductListingTeamInput = { actor: string; role?: string };

const TEAM_ROLE_OPTIONS = LISTING_TEAM_ROLE_SUGGESTIONS.map((role) => ({
id: role,
label: role,
}));

function createTeamRowId(): string {
return `team-${crypto.randomUUID()}`;
}

/**
* Saved team members are DIDs; look up their current handles so the editor
* shows `alice.bsky.social` rather than `did:plc:…`.
*/
async function fetchTeamHandles(
dids: ReadonlyArray<string>,
): Promise<Record<string, string>> {
const out: Record<string, string> = {};
for (let i = 0; i < dids.length; i += 25) {
const url = new URL(
"xrpc/app.bsky.actor.getProfiles",
"https://public.api.bsky.app",
);
for (const did of dids.slice(i, i + 25)) {
url.searchParams.append("actors", did);
}
const res = await fetch(url);
if (!res.ok) continue;
const data = (await res.json()) as {
profiles?: Array<{ did?: string; handle?: string }>;
};
for (const profile of data.profiles ?? []) {
if (profile.did && profile.handle && profile.handle !== "handle.invalid")
out[profile.did] = profile.handle;
}
}
return out;
}

const MAX_SCREENSHOT_COUNT = 4;

/** `fyi.atstore.listing.detail#tagline` maxLength. */
Expand Down Expand Up @@ -644,6 +697,16 @@ const styles = stylex.create({
alignSelf: "flex-start",
marginTop: 4,
},
teamActor: {
flexBasis: { default: "100%", [breakpoints.md]: 0 },
flexGrow: 3,
minWidth: 0,
},
teamRole: {
flexBasis: 0,
flexGrow: 2,
minWidth: 0,
},
// Footer
footerActions: {
alignItems: "center",
Expand Down Expand Up @@ -699,6 +762,8 @@ export type ProductListingFormSubmitValues = {
pendingScreenshotBlobs: Array<Blob>;
retainedScreenshotUrls: Array<string>;
links: Array<ListingLink>;
/** People behind the listing, in display order (handles or DIDs + optional role). */
team: Array<ProductListingTeamInput>;
/**
* Editorial app tags for `apps/<slug>` listings. Empty for app-tool categories
* since the lexicon only uses tags on top-level apps.
Expand All @@ -719,6 +784,7 @@ export type ProductListingFormInitialValues = {
iconUrl?: string | null;
screenshotUrls?: Array<string>;
links?: Array<ListingLink>;
team?: Array<ListingTeamMember>;
appTags?: Array<string>;
};

Expand Down Expand Up @@ -911,6 +977,31 @@ export function ProductListingForm({
const [linkRows, setLinkRows] = useState<Array<LinkRow>>(() =>
buildInitialLinkRows(initialValues.links),
);
const [teamRows, setTeamRows] = useState<Array<TeamRow>>(() =>
(initialValues.team ?? [])
.slice(0, LISTING_TEAM_MAX_COUNT)
.map((member) => ({
id: createTeamRowId(),
actor: member.did,
role: member.role ?? "",
})),
);
const initialTeamDids = (initialValues.team ?? []).map((m) => m.did);
const { data: initialTeamHandles } = useQuery({
queryKey: ["listing-team-handles", initialTeamDids],
queryFn: () => fetchTeamHandles(initialTeamDids),
enabled: initialTeamDids.length > 0,
staleTime: 5 * 60_000,
});
useEffect(() => {
if (!initialTeamHandles) return;
setTeamRows((rows) =>
rows.map((row) => {
const handle = initialTeamHandles[row.actor];
return handle ? { ...row, actor: handle } : row;
}),
);
}, [initialTeamHandles]);

const initialNormalizedAppTags = normalizeAppTags(
initialValues.appTags ?? [],
Expand Down Expand Up @@ -1006,6 +1097,35 @@ export function ProductListingForm({
});
}

function updateTeamRow(id: string, patch: Partial<TeamRow>) {
setTeamRows((rows) =>
rows.map((row) => (row.id === id ? { ...row, ...patch } : row)),
);
}

function removeTeamRow(id: string) {
setTeamRows((rows) => rows.filter((row) => row.id !== id));
}

function addTeamRow() {
setTeamRows((rows) =>
rows.length >= LISTING_TEAM_MAX_COUNT
? rows
: [...rows, { id: createTeamRowId(), actor: "", role: "" }],
);
}

function collectTeamForSubmit(): Array<ProductListingTeamInput> {
const out: Array<ProductListingTeamInput> = [];
for (const row of teamRows) {
const actor = row.actor.trim().replace(/^@+/, "");
if (!actor) continue;
const role = row.role.trim();
out.push(role ? { actor, role } : { actor });
}
return out;
}

function collectLinksForSubmit(): Array<ListingLink> {
const out: Array<ListingLink> = [];
for (const row of linkRows) {
Expand Down Expand Up @@ -1229,6 +1349,7 @@ export function ProductListingForm({
.filter((item) => item.blob == null)
.map((item) => item.previewUrl),
links: collectLinksForSubmit(),
team: collectTeamForSubmit(),
appTags: collectAppTagsForSubmit(),
});
}}
Expand Down Expand Up @@ -1824,6 +1945,76 @@ export function ProductListingForm({
</Button>
</FormCard>

<FormCard
title="Team"
description={`Optional — credit the people behind this listing: developers, designers, and anyone else. Each person links to their Bluesky profile, and the listing shows up on their at-store profile. Up to ${String(LISTING_TEAM_MAX_COUNT)}.`}
>
{teamRows.length > 0 ? (
<div {...stylex.props(styles.linkList)}>
{teamRows.map((row) => (
<div key={row.id} {...stylex.props(styles.linkRow)}>
<div {...stylex.props(styles.teamActor)}>
<UserHandleAutocomplete
size="md"
aria-label="Team member's Bluesky handle"
placeholder="handle.bsky.social"
value={row.actor}
onValueChange={(value) => {
updateTeamRow(row.id, { actor: value });
}}
/>
</div>
<ComboBox
aria-label="Role"
allowsCustomValue
menuTrigger="focus"
placeholder="Role, e.g. Developer"
items={TEAM_ROLE_OPTIONS}
inputValue={row.role}
onInputChange={(value) => {
updateTeamRow(row.id, {
role: value.slice(0, LISTING_TEAM_ROLE_MAX_LENGTH),
});
}}
onChange={(key) => {
if (key === null) return;
updateTeamRow(row.id, { role: String(key) });
}}
style={styles.teamRole}
>
{(item) => (
<ComboBoxItem id={item.id}>{item.label}</ComboBoxItem>
)}
</ComboBox>
<IconButton
size="md"
variant="tertiary"
label="Remove team member"
isDisabled={isSubmitting}
onPress={() => {
removeTeamRow(row.id);
}}
>
<X size={15} />
</IconButton>
</div>
))}
</div>
) : null}
<Button
size="sm"
variant="secondary"
isDisabled={
isSubmitting || teamRows.length >= LISTING_TEAM_MAX_COUNT
}
onPress={addTeamRow}
style={styles.addLink}
>
<Plus size={14} aria-hidden />
Add person
</Button>
</FormCard>

{errorMessage ? (
<Alert variant="critical" title={errorMessage} />
) : null}
Expand Down
Loading
Loading