mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-14 08:36:22 +08:00
58 lines
1.9 KiB
TypeScript
58 lines
1.9 KiB
TypeScript
import { FC, useState } from 'react';
|
|
import { CreateView } from '@toeverything/framework/virgo';
|
|
import {
|
|
useOnSelect,
|
|
WrapperWithPendantAndDragDrop,
|
|
} from '@toeverything/components/editor-core';
|
|
import { Upload } from '../../components/upload/upload';
|
|
import { SourceView } from '../../components/source-view';
|
|
import { styled } from '@toeverything/components/ui';
|
|
import { LinkContainer } from '../../components/style-container';
|
|
|
|
const MESSAGES = {
|
|
ADD_FIGMA_LINK: 'Add figma link',
|
|
};
|
|
|
|
interface FigmaView extends CreateView {
|
|
figmaUrl?: string;
|
|
}
|
|
export const FigmaView: FC<FigmaView> = ({ block, editor }) => {
|
|
const [figmaUrl, setFigmaUrl] = useState<string>(
|
|
block.getProperty('embedLink')?.value
|
|
);
|
|
|
|
const onFigmaUrlChange = async (link: string) => {
|
|
setFigmaUrl(link);
|
|
block.setProperty('embedLink', { value: link, name: 'figma' });
|
|
};
|
|
const [isSelect, setIsSelect] = useState<boolean>();
|
|
useOnSelect(block.id, (isSelect: boolean) => {
|
|
setIsSelect(isSelect);
|
|
});
|
|
return (
|
|
<WrapperWithPendantAndDragDrop editor={editor} block={block}>
|
|
<LinkContainer>
|
|
{figmaUrl ? (
|
|
<SourceView
|
|
block={block}
|
|
viewType="figma"
|
|
link={figmaUrl}
|
|
isSelected={isSelect}
|
|
/>
|
|
) : (
|
|
<Upload
|
|
firstCreate={block.firstCreateFlag}
|
|
uploadType={'figma'}
|
|
savaLink={onFigmaUrlChange}
|
|
deleteFile={() => {
|
|
block.remove();
|
|
}}
|
|
defaultAddBtnText={MESSAGES.ADD_FIGMA_LINK}
|
|
isSelected={isSelect}
|
|
/>
|
|
)}
|
|
</LinkContainer>
|
|
</WrapperWithPendantAndDragDrop>
|
|
);
|
|
};
|