Skip to content

Add confetti #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 27, 2024
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
17 changes: 16 additions & 1 deletion apps/web/components/layout/page.component.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Menu, Transition } from "@headlessui/react";
import { ArrowLeftIcon, CogIcon } from "@heroicons/react/solid";
import confetti from "canvas-confetti";
import classNames from "classnames";
import Link from "next/link";
import { useRouter } from "next/router";
import React, { Fragment } from "react";
import React, { Fragment, useEffect } from "react";
import { useHotkeys } from "react-hotkeys-hook";
import { useUserData } from "../../utils/useUser";
import BillingBanner from "../billing/billing-banner";
Expand Down Expand Up @@ -56,6 +57,20 @@ export default function Page({
[router, backRoute]
);

useEffect(() => {
if (router.query?.yay && confetti) {
try {
confetti({
particleCount: 100,
spread: 70,
origin: { y: 0.5 },
});
} catch (e) {
console.error(e);
}
}
}, [router.query?.yay]);

return (
<>
<header className="bg-white dark:bg-black shadow dark:shadow-sm dark:shadow-gray-700/50 sticky top-0 z-10 backdrop-filter backdrop-blur-lg bg-opacity-70 dark:bg-opacity-70">
Expand Down
4 changes: 3 additions & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
"@supabase/auth-ui-shared": "^0.1.8",
"@supabase/supabase-js": "^2.39.3",
"@tailwindcss/typography": "^0.5.1",
"@types/canvas-confetti": "^1.6.4",
"@upstash/redis": "^1.20.6",
"@vercel/analytics": "^1.0.1",
"@vercel/og": "^0.0.20",
"chrono-node": "^2.5.0",
"canvas-confetti": "^1.9.3",
"chrono-node": "^2.7.6",
"classnames": "^2.3.1",
"easymde": "^2.18.0",
"eslint-config-next": "^14.0.4",
Expand Down
5 changes: 5 additions & 0 deletions apps/web/pages/pages/[page_id]/new.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PostStatus } from "@changes-page/supabase/types/page";
import { InferGetServerSidePropsType } from "next";
import { useRouter } from "next/router";
import { useState } from "react";
Expand Down Expand Up @@ -52,6 +53,10 @@ export default function NewPost({

track("PostCreated");

if (values.status !== PostStatus.draft) {
return await router.replace(`${ROUTES.PAGES}/${page_id}?yay=true`);
}

return await router.replace(`${ROUTES.PAGES}/${page_id}`);
} catch (_) {
setSaving(false);
Expand Down
2 changes: 1 addition & 1 deletion apps/web/pages/pages/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default function NewPage() {
url_slug: values.url_slug,
});

return await router.push(ROUTES.PAGES);
return await router.push(ROUTES.PAGES + "?yay=true");
} catch (e) {
notifyError();
setSaving(false);
Expand Down
18 changes: 11 additions & 7 deletions apps/web/utils/revalidate.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { httpPost } from "./http";

export const revalidatePage = async (path: string) => {
const revalidateEndpoint =
process.env.REVALIDATE_ENDPOINT || "https://hey.changes.page";
try {
const revalidateEndpoint =
process.env.REVALIDATE_ENDPOINT || "https://hey.changes.page";

const result = await httpPost({
url: `${revalidateEndpoint}/api/revalidate?secret=${process.env.REVALIDATE_TOKEN}`,
data: { path },
});
const result = await httpPost({
url: `${revalidateEndpoint}/api/revalidate?secret=${process.env.REVALIDATE_TOKEN}`,
data: { path },
});

console.log("revalidatePage: Result:", path, result);
console.log("revalidatePage: Result:", path, result);
} catch (error) {
console.error("revalidatePage failed: Error:", error);
}
};
22 changes: 18 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.