Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

1.2 KB
Raw Blame
'use client';

import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';
import * as stylex from '@stylexjs/stylex';
import { useParams } from 'react-router';
import useSWR from 'swr';

import { shareKeys } from '@/libs/swr/keys';
import { lambdaClient } from '@/libs/trpc/client';

import ShareLayout from '../../shell/ShareLayout';

const styles = stylex.create({
  frame: {
    width: '100%',
    height: '100%',
    borderStyle: 'none',
    backgroundColor: cssVar.colorBgLayout,
    backgroundImage: 'none',
  },
});

const SharedArtifactView = () => {
  const { id } = useParams<{ id: string }>();

  const { data, error, isLoading } = useSWR(
    id ? shareKeys.artifact(id) : null,
    () => lambdaClient.artifactShare.getShared.query({ id: id! }),
    { revalidateOnFocus: false },
  );

  const loading = isLoading && !data;

  return (
    <ShareLayout error={error || (!loading && !data)} loading={loading} title={data?.title}>
      {data && (
        <iframe
          {...stylex.props(styles.frame)}
          referrerPolicy={'no-referrer'}
          sandbox={'allow-scripts'}
          src={data.iframeSrc}
          title={data.title ?? 'Artifact'}
        />
      )}
    </ShareLayout>
  );
};

export default SharedArtifactView;