Skip to content

Commit

Permalink
bug: bug fix on copying code 🐛
Browse files Browse the repository at this point in the history
  • Loading branch information
tonalmathew committed Feb 1, 2022
1 parent 29bfe4d commit 217a387
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "markdown-compiler",
"version": "0.1.0",
"version": "0.1.1",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
Expand Down
80 changes: 67 additions & 13 deletions src/components/CopyButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,77 @@ export default {
data() {
return {
popoverShow: false,
shareFailed: true,
};
},
computed: {
},
methods: {
isASupportedBrowser() {
var ua = navigator.userAgent || navigator.vendor || window.opera;
return (
navigator.userAgent.indexOf("Firefox") === -1 &&
ua.indexOf("FBAN") === -1 &&
ua.indexOf("FBAV") === -1 &&
ua.indexOf("Instagram") === -1
);
},
async copy() {
await navigator.clipboard
.writeText(this.$props.textToCopy)
.then(() => {
this.popoverShow
? (this.popoverShow = false)
: (this.popoverShow = true);
createPopper(this.$refs.btnRef, this.$refs.popoverRef, {
placement: "top",
});
})
.catch((err) => {
alert("Error in copying text: ", err);
});
const text = this.$props.textToCopy;
this.shareFailed = true;
try {
if (navigator.canShare && this.isASupportedBrowser()) {
console.log("yes");
const shareData = {
text,
};
if (navigator.canShare(shareData)) {
await navigator.share(shareData);
this.shareFailed = false;
}
}
} catch (err) {
console.log(err);
if (err.code === DOMException.ABORT_ERR) {
this.shareFailed = false;
}
}
try {
if (this.shareFailed) {
await navigator.clipboard
.writeText(text)
.then(() => {
this.popoverShow
? (this.popoverShow = false)
: (this.popoverShow = true);
createPopper(this.$refs.btnRef, this.$refs.popoverRef, {
placement: "top",
});
})
.catch((err) => {
alert("Error in copying text: ", err);
});
// this.showMessage("Copied results to clipboard!", 2000);
}
} catch (err) {
alert("Share Failed. Try A Different Web Browser");
console.log(err);
}
// await navigator.clipboard
// .writeText(text)
// .then(() => {
// this.popoverShow
// ? (this.popoverShow = false)
// : (this.popoverShow = true);
// createPopper(this.$refs.btnRef, this.$refs.popoverRef, {
// placement: "top",
// });
// })
// .catch((err) => {
// alert("Error in copying text: ", err);
// });
},
},
};
Expand Down

0 comments on commit 217a387

Please sign in to comment.