a tool for shared writing and social publishing
1"use client"; 2import Link from "next/link"; 3import { useEntitySetContext } from "./EntitySetProvider"; 4import { ActionButton } from "components/ActionBar/ActionButton"; 5import { useParams, useSearchParams } from "next/navigation"; 6import { useIdentityData } from "./IdentityProvider"; 7import { useReplicache } from "src/replicache"; 8import { addLeafletToHome } from "actions/addLeafletToHome"; 9import { useSmoker } from "./Toast"; 10import { AddToHomeSmall } from "./Icons/AddToHomeSmall"; 11import { HomeSmall } from "./Icons/HomeSmall"; 12import { permission } from "process"; 13 14export function HomeButton() { 15 let { permissions } = useEntitySetContext(); 16 let searchParams = useSearchParams(); 17 18 return ( 19 <> 20 <Link 21 href="/home" 22 prefetch 23 className="hover:no-underline" 24 style={{ textDecorationLine: "none !important" }} 25 > 26 <ActionButton icon={<HomeSmall />} label="Go Home" /> 27 </Link> 28 {<AddToHomeButton />} 29 </> 30 ); 31} 32 33const AddToHomeButton = (props: {}) => { 34 let { permission_token } = useReplicache(); 35 let { identity, mutate } = useIdentityData(); 36 let smoker = useSmoker(); 37 if ( 38 identity?.permission_token_on_homepage.find( 39 (pth) => pth.permission_tokens.id === permission_token.id, 40 ) || 41 !identity 42 ) 43 return null; 44 return ( 45 <ActionButton 46 onClick={async (e) => { 47 await addLeafletToHome(permission_token.id); 48 mutate((identity) => { 49 if (!identity) return; 50 return { 51 ...identity, 52 permission_token_on_homepage: [ 53 ...identity.permission_token_on_homepage, 54 { 55 created_at: new Date().toISOString(), 56 permission_tokens: { 57 ...permission_token, 58 leaflets_in_publications: [], 59 }, 60 }, 61 ], 62 }; 63 }); 64 smoker({ 65 position: { 66 x: e.clientX + 64, 67 y: e.clientY, 68 }, 69 text: "Leaflet added to your home!", 70 }); 71 }} 72 icon={<AddToHomeSmall />} 73 label="Add to Home" 74 /> 75 ); 76};