From b19c5d589638535289ec73665ce318466277b92d Mon Sep 17 00:00:00 2001 From: Ashish Padhy <100484401+Shurtu-gal@users.noreply.github.com> Date: Sun, 14 May 2023 02:41:24 +0530 Subject: [PATCH 1/3] feat: add share functionality --- src/components/Editor/EditorSidebar.tsx | 15 ++++++++--- src/components/Editor/ShareButton.tsx | 36 +++++++++++++++++++++++++ src/services/editor.service.tsx | 10 +++++++ 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 src/components/Editor/ShareButton.tsx diff --git a/src/components/Editor/EditorSidebar.tsx b/src/components/Editor/EditorSidebar.tsx index b854db5c2..c8e304796 100644 --- a/src/components/Editor/EditorSidebar.tsx +++ b/src/components/Editor/EditorSidebar.tsx @@ -3,11 +3,14 @@ import React from 'react'; import { EditorDropdown } from './EditorDropdown'; import { useFilesState } from '../../state'; +import { ShareButton } from './ShareButton'; interface EditorSidebarProps {} -export const EditorSidebar: React.FunctionComponent = () => { - const { source, from } = useFilesState(state => state.files['asyncapi']); +export const EditorSidebar: React.FunctionComponent< + EditorSidebarProps +> = () => { + const { source, from } = useFilesState((state) => state.files['asyncapi']); let documentFromText = ''; if (from === 'storage') { @@ -23,7 +26,10 @@ export const EditorSidebar: React.FunctionComponent = () => className="flex flex-row items justify-between bg-gray-800 border-b border-gray-700 text-sm" style={{ height: '30px', lineHeight: '30px' }} > -
+
{documentFromText}
= () => >
    +
  • + +
  • diff --git a/src/components/Editor/ShareButton.tsx b/src/components/Editor/ShareButton.tsx new file mode 100644 index 000000000..5bd6320aa --- /dev/null +++ b/src/components/Editor/ShareButton.tsx @@ -0,0 +1,36 @@ +import React from 'react'; +import { FaShareAlt } from 'react-icons/fa'; +import { useServices } from '../../services'; +import { toast } from 'react-hot-toast'; +import { Tooltip } from '../common'; + +interface ShareButtonProps {} + +export const ShareButton: React.FunctionComponent = () => { + const { editorSvc } = useServices(); + + const handleShare = () => { + toast.promise( + (async function () { + const base64 = await editorSvc.exportAsBase64(); + const url = `${window.location.origin}/?base64=${encodeURIComponent( + base64 + )}`; + navigator.clipboard.writeText(url); + }()), + { + loading: 'Copying URL to clipboard...', + success: 'URL copied to clipboard!', + error: 'Failed to copy URL to clipboard.', + } + ); + }; + + return ( + + + + ); +}; diff --git a/src/services/editor.service.tsx b/src/services/editor.service.tsx index 9157bc83f..2d54a9dd9 100644 --- a/src/services/editor.service.tsx +++ b/src/services/editor.service.tsx @@ -157,6 +157,16 @@ export class EditorService extends AbstractService { } } + async exportAsBase64() { + try { + const file = filesState.getState().files['asyncapi']; + return this.svcs.formatSvc.encodeBase64(file.content); + } catch (err) { + console.error(err); + throw err; + } + } + async convertToYaml() { try { const yamlContent = this.svcs.formatSvc.convertToYaml(this.value); From 98e0215f665d36e0821be20b0b253601083de664 Mon Sep 17 00:00:00 2001 From: Ashish Padhy <100484401+Shurtu-gal@users.noreply.github.com> Date: Sun, 14 May 2023 02:45:49 +0530 Subject: [PATCH 2/3] chore: fix promise await --- src/components/Editor/ShareButton.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Editor/ShareButton.tsx b/src/components/Editor/ShareButton.tsx index 5bd6320aa..96f4b9481 100644 --- a/src/components/Editor/ShareButton.tsx +++ b/src/components/Editor/ShareButton.tsx @@ -16,7 +16,7 @@ export const ShareButton: React.FunctionComponent = () => { const url = `${window.location.origin}/?base64=${encodeURIComponent( base64 )}`; - navigator.clipboard.writeText(url); + await navigator.clipboard.writeText(url); }()), { loading: 'Copying URL to clipboard...', From 0a1aebffccd8e3868ebe24d2da93913b1d549446 Mon Sep 17 00:00:00 2001 From: Ashish Padhy <100484401+Shurtu-gal@users.noreply.github.com> Date: Tue, 26 Sep 2023 19:46:13 +0530 Subject: [PATCH 3/3] fix: TS errors --- apps/studio/src/services/parser.service.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/studio/src/services/parser.service.ts b/apps/studio/src/services/parser.service.ts index 0fd3a5650..fc01d535b 100644 --- a/apps/studio/src/services/parser.service.ts +++ b/apps/studio/src/services/parser.service.ts @@ -10,6 +10,7 @@ import { filesState, documentsState, settingsState } from '../state'; import type { Diagnostic, ParseOptions } from '@asyncapi/parser/cjs'; import type { DocumentDiagnostics } from '../state/documents.state'; +import { SchemaParser } from '@asyncapi/parser'; export class ParserService extends AbstractService { private parser!: Parser; @@ -17,8 +18,9 @@ export class ParserService extends AbstractService { override async onInit() { this.parser = new Parser({ schemaParsers: [ - OpenAPISchemaParser(), - AvroSchemaParser(), + // Temporary fix for TS error + OpenAPISchemaParser() as SchemaParser, + AvroSchemaParser() as SchemaParser, ], __unstable: { resolver: {