import { useAuth } from '@redwoodjs/auth' import { useMutation } from '@redwoodjs/web' import { Popover } from '@headlessui/react' import { Link, navigate, routes } from '@redwoodjs/router' import { Tab, Tabs, TabList, TabPanel } from 'react-tabs' import FullScriptEncoding from 'src/components/EncodedUrl/FullScriptEncoding' import ExternalScript from 'src/components/EncodedUrl/ExternalScript' import Svg from 'src/components/Svg/Svg' import { toast } from '@redwoodjs/web/toast' import CaptureButton from 'src/components/CaptureButton/CaptureButton' import { useIdeContext } from 'src/helpers/hooks/useIdeContext' import Gravatar from 'src/components/Gravatar/Gravatar' import EditableProjectTitle from 'src/components/EditableProjecTitle/EditableProjecTitle' const FORK_PROJECT_MUTATION = gql` mutation ForkProjectMutation($input: ForkProjectInput!) { forkProject(input: $input) { id title user { id userName } } } ` const TopButton = ({ onClick, children, className, name, Tag = 'button', }: { onClick?: () => void children: React.ReactNode className?: string name: string Tag?: string }) => { const FinalTag = Tag as unknown as keyof JSX.IntrinsicElements return ( {children} {name} ) } export default function IdeHeader({ handleRender, context, }: { handleRender?: () => void context: 'ide' | 'profile' }) { const { currentUser } = useAuth() const { project } = useIdeContext() const isProfile = context === 'profile' const canEdit = (currentUser && currentUser?.sub === project?.user?.id) || currentUser?.roles?.includes('admin') const projectOwner = project?.user?.userName const [createFork] = useMutation(FORK_PROJECT_MUTATION, { onCompleted: ({ forkProject }) => { const params = { userName: forkProject?.user?.userName, projectTitle: forkProject?.title, } navigate(!isProfile ? routes.ide(params) : routes.project(params)) }, }) const handleFork = () => { const prom = createFork({ variables: { input: { userId: currentUser.sub, forkedFromId: project?.id, }, }, }) toast.promise(prom, { loading: 'Forking...', success: Forked successfully!, error: Problem forking., }) } return ( <>
{project?.id && ( <> {projectOwner} )}
{canEdit && !isProfile && ( ( )} /> )} {!isProfile && ( )} {isProfile && ( navigate( routes.ide({ userName: projectOwner, projectTitle: project.title, }) ) } name="Editor" > )} {({ open }) => { return ( <> {open && ( encoded script external script )} ) }} {currentUser?.sub && ( )}
) }