feat: OS Share Target for recipe URLs (v0.67.0)
Declares share_target in manifest.ts (action /recipes, GET, title/text/url params). recipes/page.tsx extracts the shared link -- preferring the url param, falling back to the first http(s) URL found inside text since senders vary on where they put it -- and passes it to RecipesHeader as sharedUrl. UrlImportDialog gained initialUrl/autoImport props so the existing import-from-URL flow opens pre-filled and fires immediately instead of requiring the user to paste the link back in. Chromium/Android only -- Safari has no Share Target API at all, same restriction already documented for the install-prompt banner. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -24,8 +24,25 @@ type SearchParams = Promise<{
|
||||
page?: string;
|
||||
batchCook?: string;
|
||||
recipeType?: string;
|
||||
// OS Share Target params (manifest.ts's share_target) — a browser share
|
||||
// sheet navigates here with these appended.
|
||||
url?: string;
|
||||
text?: string;
|
||||
title?: string;
|
||||
}>;
|
||||
|
||||
const URL_PATTERN = /https?:\/\/\S+/;
|
||||
|
||||
/** Web Share Target's GET params vary by sender: some apps put the shared
|
||||
* link in `url`, others (notably many Android apps) put it inside `text`
|
||||
* alongside other text. Prefer `url`, fall back to extracting the first
|
||||
* http(s) URL out of `text`. */
|
||||
function extractSharedUrl(params: { url?: string; text?: string }): string | undefined {
|
||||
if (params.url && URL_PATTERN.test(params.url)) return params.url;
|
||||
const match = params.text?.match(URL_PATTERN);
|
||||
return match?.[0];
|
||||
}
|
||||
|
||||
const SORT_MAP = {
|
||||
updated_desc: desc(recipes.updatedAt),
|
||||
updated_asc: asc(recipes.updatedAt),
|
||||
@@ -43,7 +60,8 @@ export default async function RecipesPage({ searchParams }: { searchParams: Sear
|
||||
const m = getMessages((session.user as { locale?: string }).locale);
|
||||
const featurePrefs = await getFeaturePrefs(session.user.id);
|
||||
|
||||
const { q, sort, visibility, difficulty, tag, page: pageParam, batchCook, recipeType } = await searchParams;
|
||||
const { q, sort, visibility, difficulty, tag, page: pageParam, batchCook, recipeType, url, text } = await searchParams;
|
||||
const sharedUrl = extractSharedUrl({ url, text });
|
||||
const query = (q ?? "").trim().slice(0, 200);
|
||||
const sortKey: SortKey = (sort && sort in SORT_MAP ? sort : "updated_desc") as SortKey;
|
||||
const tagFilter = tag?.trim().slice(0, 50) || undefined;
|
||||
@@ -140,6 +158,7 @@ export default async function RecipesPage({ searchParams }: { searchParams: Sear
|
||||
initialTag={tagFilter ?? ""}
|
||||
initialBatchCook={batchCookFilter ?? ""}
|
||||
initialRecipeType={recipeTypeFilter ?? ""}
|
||||
sharedUrl={sharedUrl}
|
||||
/>
|
||||
<RecipesEmptyState query={query} count={total} />
|
||||
<RecipesGrid key={`${query}-${sortKey}-${visibilityFilter}-${difficultyFilter}-${tagFilter}-${batchCookFilter}-${recipeTypeFilter}-${page}`} recipes={recipesWithFavorites} />
|
||||
|
||||
@@ -15,5 +15,18 @@ export default function manifest(): MetadataRoute.Manifest {
|
||||
{ src: "/icon-512.svg", sizes: "512x512", type: "image/svg+xml", purpose: "any" },
|
||||
{ src: "/icon-512.svg", sizes: "512x512", type: "image/svg+xml", purpose: "maskable" },
|
||||
],
|
||||
// Registers Epicure as a share target in the OS share sheet (Chromium
|
||||
// on Android/desktop once installed — Safari has no equivalent API).
|
||||
// Sharing a recipe link from another app opens /recipes with these
|
||||
// query params, which auto-opens the URL-import dialog pre-filled.
|
||||
share_target: {
|
||||
action: "/recipes",
|
||||
method: "GET",
|
||||
params: {
|
||||
title: "title",
|
||||
text: "text",
|
||||
url: "url",
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user