Skip to content

Commit

Permalink
integrate with share link feature
Browse files Browse the repository at this point in the history
  • Loading branch information
dontry committed Nov 11, 2023
1 parent 4167ec8 commit 428bc5e
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 163 deletions.
18 changes: 15 additions & 3 deletions src/components/ContentWrap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Toolbox from './Toolbox.jsx';
import Tabs from './Tabs.jsx';
import { computeCss, computeHtml, computeJs } from '../computes';
import { CssModes, HtmlModes, JsModes, modes } from '../codeModes';
import { getCompleteHtml, loadJS, log, blobToBase64 } from '../utils';
import { getCompleteHtml, loadJS, log } from '../utils';

import { Button } from './common';
import { SplitPane } from './SplitPane.jsx';
Expand All @@ -32,6 +32,8 @@ export default class ContentWrap extends Component {
lineOfCode: 0,
isConsoleOpen: false,
isCssSettingsModalOpen: false,
imageBase64: null,
isSharePanelVisible: false,
};
this.updateTimer = null;
this.updateDelay = 500;
Expand Down Expand Up @@ -459,8 +461,13 @@ export default class ContentWrap extends Component {
}

async shareClickHandler(e) {
const imageBlob = await this.getPngBlob();
this.props.currentItem.imageBase64 = await blobToBase64(imageBlob);
if (!window.user) {
this.props.onLogin();
return;
}
const image = await this.getPngBlob();
await this.props.onUpdateImage(image);
this.setState({ isSharePanelVisible: true });
trackEvent('ui', 'shareLink');
}

Expand Down Expand Up @@ -1047,6 +1054,10 @@ export default class ContentWrap extends Component {
closeOnBlur={true}
hasArrow={true}
placement={'bottom'}
onVisibilityChange={(visible) =>
this.setState({ isSharePanelVisible: visible })
}
isVisible={this.state.isSharePanelVisible}
trigger={
<Button
className="button icon-button hint--rounded hint--bottom-left"
Expand All @@ -1063,6 +1074,7 @@ export default class ContentWrap extends Component {
<SharePanel
author={window.user ? window.user.displayName : 'author'}
currentItem={this.props.currentItem}
imageBase64={this.state.imageBase64}
/>
}
/>
Expand Down
11 changes: 7 additions & 4 deletions src/components/PopOver.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ export class Popover extends Component {
}

componentDidMount() {
this.props.closeOnBlur &&
document.addEventListener('click', this.handleDocumentClick, true);
document.addEventListener(
'click',
this.handleDocumentClick.bind(this),
true
);
}

componentWillUnmount() {
this.props.closeOnBlur &&
document.removeEventListener('click', this.handleDocumentClick);
document.removeEventListener('click', this.handleDocumentClick.bind(this));
}

togglePopover = () => {
Expand All @@ -36,6 +38,7 @@ export class Popover extends Component {
this.popoverRef.current &&
!this.popoverRef.current.contains(event.target)
) {
this.props.onVisibilityChange && this.props.onVisibilityChange(false);
this.setState({ isVisible: false });
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/components/PreviewCard.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PropTypes from 'prop-types';

export function PreviewCard({ title, author, description, image }) {
export function PreviewCard({ title, author, description, imageBase64 }) {
return (
<div className="preview-card">
<div className="preview-card__content">
Expand All @@ -22,7 +22,7 @@ export function PreviewCard({ title, author, description, image }) {
</div>
<div className="preview-card__image">
<div className="overlay">
<img src={image} />
<img src={imageBase64} />
</div>
</div>
</div>
Expand All @@ -33,5 +33,5 @@ PreviewCard.propTypes = {
title: PropTypes.string.isRequired,
author: PropTypes.string.isRequired,
description: PropTypes.string.isRequired,
image: PropTypes.string,
imageBase64: PropTypes.string,
};
18 changes: 16 additions & 2 deletions src/components/SharePanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@ export class SharePanel extends Component {
}

async componentDidMount() {
const result = await syncDiagram(this.props.currentItem);
await this.syncDiagram(this.props.currentItem);
}

async componentDidUpdate(prevProps) {
if (prevProps.currentItem !== this.props.currentItem) {
await this.syncDiagram(this.props.currentItem);
}
}

async syncDiagram(currentItem) {
const result = await syncDiagram(currentItem);
if (!result) {
return;
}
this.setState({
isLoading: false,
link: getShareLink(result),
Expand Down Expand Up @@ -56,7 +69,7 @@ export class SharePanel extends Component {
title={currentItem.title}
author={author}
description="Click and check the latest diagram. Install our Confluence plugin for an enhanced expperience when viewing in Confluence."
image={currentItem.imageBase64}
imageBase64={currentItem.imageBase64}
/>
<Popover
isVisible={this.state.isTooltipVisible}
Expand All @@ -68,6 +81,7 @@ export class SharePanel extends Component {
className="button icon-button copy-button"
title={link}
onClick={this.handleCopyLink}
disabled={isLoading}
>
{isLoading ? (
<div className="loader" />
Expand Down
Loading

0 comments on commit 428bc5e

Please sign in to comment.