Something went wrong. Try again.
a tool for shared writing and social publishing
Something went wrong. Try again.
2.2 kB · 76 lines
TSX
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677"use client";import Link from "next/link";import { useEntitySetContext } from "./EntitySetProvider";import { ActionButton } from "components/ActionBar/ActionButton";import { useParams, useSearchParams } from "next/navigation";import { useIdentityData } from "./IdentityProvider";import { useReplicache } from "src/replicache";import { addLeafletToHome } from "actions/addLeafletToHome";import { useSmoker } from "./Toast";import { AddToHomeSmall } from "./Icons/AddToHomeSmall";import { HomeSmall } from "./Icons/HomeSmall";import { permission } from "process";
export function HomeButton() { let { permissions } = useEntitySetContext(); let searchParams = useSearchParams();
return ( <> <Link href="/home" prefetch className="hover:no-underline" style={{ textDecorationLine: "none !important" }} > <ActionButton icon={<HomeSmall />} label="Go Home" /> </Link> {<AddToHomeButton />} </> );}
const AddToHomeButton = (props: {}) => { let { permission_token } = useReplicache(); let { identity, mutate } = useIdentityData(); let smoker = useSmoker(); if ( identity?.permission_token_on_homepage.find( (pth) => pth.permission_tokens.id === permission_token.id, ) || !identity ) return null; return ( <ActionButton onClick={async (e) => { await addLeafletToHome(permission_token.id); mutate((identity) => { if (!identity) return; return { ...identity, permission_token_on_homepage: [ ...identity.permission_token_on_homepage, { created_at: new Date().toISOString(), permission_tokens: { ...permission_token, leaflets_in_publications: [], }, }, ], }; }); smoker({ position: { x: e.clientX + 64, y: e.clientY, }, text: "Leaflet added to your home!", }); }} icon={<AddToHomeSmall />} label="Add to Home" /> );};