fix: clarify empty fishing plan shares
This commit is contained in:
@@ -31,7 +31,13 @@ import Layout from "../layouts/Layout.astro";
|
||||
catch { return []; }
|
||||
};
|
||||
const shared = new URLSearchParams(location.search).get("plan");
|
||||
if (shared) { try { const imported = normalisePlan(JSON.parse(shared)); if (imported.length) localStorage.setItem(planStorageKey, JSON.stringify(imported)); } catch { if (shareStatus) shareStatus.textContent = "Ссылка плана не распознана"; } }
|
||||
if (shared) {
|
||||
try {
|
||||
const imported = normalisePlan(JSON.parse(shared));
|
||||
if (imported.length) localStorage.setItem(planStorageKey, JSON.stringify(imported));
|
||||
else if (shareStatus) shareStatus.textContent = "В ссылке нет сохранённых точек";
|
||||
} catch { if (shareStatus) shareStatus.textContent = "Ссылка плана не распознана"; }
|
||||
}
|
||||
const render = () => {
|
||||
if (!list || !empty) return;
|
||||
const plan = readPlan();
|
||||
@@ -52,7 +58,9 @@ import Layout from "../layouts/Layout.astro";
|
||||
});
|
||||
};
|
||||
document.querySelector<HTMLButtonElement>("[data-plan-share]")?.addEventListener("click", async () => {
|
||||
const url = new URL(location.href); url.search = ""; url.searchParams.set("plan", JSON.stringify(readPlan()));
|
||||
const plan = readPlan();
|
||||
if (!plan.length) { if (shareStatus) shareStatus.textContent = "Сначала добавьте точку в план"; return; }
|
||||
const url = new URL(location.href); url.search = ""; url.searchParams.set("plan", JSON.stringify(plan));
|
||||
try {
|
||||
if (navigator.share) await navigator.share({ title: "Мой план рыбалки RF4", url: url.toString() });
|
||||
else await navigator.clipboard.writeText(url.toString());
|
||||
|
||||
@@ -94,3 +94,16 @@ test("plan import deduplicates the same point before applying the five-item cap"
|
||||
"/spots/vyunok-7450x7451",
|
||||
]);
|
||||
});
|
||||
|
||||
test("plan explains empty and malformed share states", async ({ page }) => {
|
||||
await page.goto("/plan");
|
||||
await page.getByRole("button", { name: "Поделиться планом" }).click();
|
||||
await expect(page.locator("[data-plan-share-status]")).toHaveText("Сначала добавьте точку в план");
|
||||
|
||||
await page.goto("/plan?plan=not-json");
|
||||
await expect(page.locator("[data-plan-share-status]")).toHaveText("Ссылка плана не распознана");
|
||||
|
||||
const emptyPlan = encodeURIComponent(JSON.stringify([]));
|
||||
await page.goto(`/plan?plan=${emptyPlan}`);
|
||||
await expect(page.locator("[data-plan-share-status]")).toHaveText("В ссылке нет сохранённых точек");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user