Skip to content

Commit

Permalink
Fix some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Shailesh351 committed Jan 23, 2020
1 parent 1c4df19 commit d105f68
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 22 deletions.
31 changes: 13 additions & 18 deletions app/lib/client/defaultTabBars.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Session } from 'meteor/session';

import { TabBar, popover } from '../../ui-utils';
import { isMobile, share } from '../../utils';
import { share, isShareAvailable } from '../../utils';
import { Rooms } from '../../models';
import { hasAllPermission } from '../../authorization';

Expand Down Expand Up @@ -72,26 +72,21 @@ TabBar.addButton({
order: 4,
});

TabBar.addButton({
// Add Share button in Room
const shareButton = {
groups: ['channel', 'group', 'direct'],
id: 'share',
i18nTitle: 'Share',
icon: 'share',
template: 'share',
order: 500,
// action(event) {
// console.log(event);
// share();
// popover.close();
// const options = [];
// const config = {
// template: 'share',
// // currentTarget: e.target,
// data: {
// options,
// },
// // offsetVertical: e.target.clientHeight + 10,
// };
// popover.open(config);
// },
});
};

if (isShareAvailable()) {
shareButton.action = () => {
share();
popover.close();
};
}

TabBar.addButton(shareButton);
1 change: 1 addition & 0 deletions app/theme/client/imports/components/share.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
cursor: pointer;
background-color: transparent;
padding: 16px 0;
box-shadow: inset 0 0 20px rgba(0,0,0, 0);

&:hover {
box-shadow: inset 0 0 20px rgba(0,0,0, .125);
Expand Down
26 changes: 23 additions & 3 deletions app/ui-share/client/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,33 @@ function getShareString() {
return `${ data.title } \n${ data.url } \n${ data.text }`;
}

function fallbackCopyTextToClipboard(text) {
const textArea = document.createElement('textarea');
textArea.value = text;
textArea.style.position = 'fixed'; // avoid scrolling to bottom
document.body.appendChild(textArea);
textArea.focus();
textArea.select();

try {
document.execCommand('copy');
} catch (err) {
console.error('Unable to copy', err);
}

document.body.removeChild(textArea);
}

Template.share.helpers({

});

Template.share.events({
'click [data-type="copy"]'() {
console.log(getShareString());
if (!navigator.clipboard) {
fallbackCopyTextToClipboard(getShareString());
return;
}
navigator.clipboard.writeText(getShareString());
},
'click [data-type="print"]'() {
Expand All @@ -24,7 +44,7 @@ Template.share.events({
window.open(`mailto:?subject=${ title }&body=${ getShareString() }`);
},
'click [data-type="sms"]'() {
location.href = `sms:'Pick a contact'?&body=${ getShareString() }`;
location.href = `sms:?&body=${ getShareString() }`;
},


Expand All @@ -44,7 +64,7 @@ Template.share.events({
},
'click [data-type="telegram"]'() {
const { url } = getShareData();
window.open(isMobile() ? `tg://msg?text=${ getShareString() }` : `https://telegram.me/share/msg?url=${ url }&text=${ getShareString() }`);
window.open(`https://telegram.me/share/msg?url=${ url }&text=${ getShareString() }`);
},

});
5 changes: 4 additions & 1 deletion app/utils/client/lib/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { Meteor } from 'meteor/meteor';

// TODO: Remove logs

export const isShareAvailable = () => navigator.share;
export const isShareAvailable = () => {
if (navigator.share) { return true; }
return false;
};

export const getShareData = () => {
const data = {};
Expand Down

0 comments on commit d105f68

Please sign in to comment.