Skip to content

Click share link now calls LaraSite directly #759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions src/services/syncService.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import firebase from 'firebase/app';

const larasiteBaseUrl = 'https://sequence-diagram.zenuml.com';
const publicBaseUrl = 'https://zenuml.com/sequence-diagram';

async function syncDiagram(currentItem) {
if (location.host === 'localhost:8080') {
console.log('Skipping sync-diagram call in local environment');
return;
}
// if (location.host === 'localhost:8080') {
// console.log('Skipping sync-diagram call in local environment');
// return;
// }

const { id, title, js } = currentItem;
if (!js || !title) {
Expand All @@ -15,28 +18,44 @@ async function syncDiagram(currentItem) {
return;
}

const token = await firebase.auth().currentUser.getIdToken(true);
const currentUser = firebase.auth().currentUser;
if (!currentUser) {
console.error('No user is logged in');
return;
}

const token = await currentUser.getIdToken(true);
const user = {
name: currentUser.displayName,
id: currentUser.uid,
email: currentUser.email,
email_verified: currentUser.emailVerified,
picture: currentUser.photoURL,
};

const data = {
token,
id,
user,
firebase_diagram_id: id,
name: title,
content: js,
description: 'Shared diagram from https://app.zenuml.com',
};
console.log('calling /sync-diagram with data:', data);
console.log('calling LaraSite with data:', data);
try {
const response = await fetch('/sync-diagram', {
const response = await fetch(`${larasiteBaseUrl}/diagrams`, {
method: 'POST',
body: JSON.stringify(data),
headers: { 'Content-Type': 'application/json' },
});
const result = await response.json();
console.log('save to php app result: ', result);

result.page_share = result.page_share.replace(larasiteBaseUrl.replace('https://', 'http://'), publicBaseUrl);
console.log('save to LaraSite result: ', result);
return result;
} catch (error) {
console.warn('Error when calling /sync-diagram', error);
throw Error('Error when calling /sync-diagram');
console.warn('Error when calling LaraSite', error);
throw Error('Error when calling LaraSite');
}
}

Expand Down