Skip to content

Commit

Permalink
feat: ✨ Share button
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatOneCalculator committed Apr 4, 2022
1 parent 4f62e7f commit fff67c1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions frontend/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ html(lang='en')
span.viewcounter.noselect#viewcounter-count(style='visibility: hidden; display: none')

.bottom-button-wrapper
button#share-button.btn(aria-label='Share' style='visibility: hidden')
button#hide-button.btn(aria-label='Hide')

.scrollbar-container
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
EyeInvisibleOutlined,
FireOutlined,
FileMarkdownOutlined,
ShareAltOutlined,
} from "@ant-design/icons-svg"
import { renderIconDefinitionToSVGElement } from "@ant-design/icons-svg/es/helpers"
import tippy from "tippy.js"
Expand All @@ -22,9 +23,11 @@ const newButton = <HTMLButtonElement>document.getElementById("new-button")
const copyButton = <HTMLButtonElement>document.getElementById("copy-button")
const hideButton = <HTMLButtonElement>document.getElementById("hide-button")
const githubButton = <HTMLButtonElement>document.getElementById("github-button")
const shareButton = <HTMLButtonElement>document.getElementById("share-button")
const markdownButton = <HTMLButtonElement>(
document.getElementById("markdown-button")
)

const singleViewButton = <HTMLButtonElement>(
document.getElementById("single-view-button")
)
Expand All @@ -47,6 +50,7 @@ renderIcon(githubButton, GithubOutlined)
renderIcon(hideButton, EyeInvisibleOutlined)
renderIcon(markdownButton, FileMarkdownOutlined)
renderIcon(singleViewButton, FireOutlined)
renderIcon(shareButton, ShareAltOutlined)

tippy("#save-button", {
content: "Save paste<br><span class='keybind'>Ctrl + S</span>",
Expand Down Expand Up @@ -112,6 +116,14 @@ tippy("#hide-button", {
allowHTML: true,
})

tippy("#share-button", {
content: "Share paste",
placement: "top",
animation: "scale",
theme: "rosepine",
allowHTML: true,
})

const observer = new MutationObserver(callback)

function callback() {
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const saveButton = <HTMLButtonElement>document.getElementById("save-button")
const newButton = <HTMLButtonElement>document.getElementById("new-button")
const copyButton = <HTMLButtonElement>document.getElementById("copy-button")
const hideButton = <HTMLButtonElement>document.getElementById("hide-button")
const shareButton = <HTMLButtonElement>document.getElementById("share-button")
const markdownButton = <HTMLButtonElement>(
document.getElementById("markdown-button")
)
Expand Down Expand Up @@ -127,6 +128,7 @@ function newPaste() {
hide(codeViewPre)
hide(viewCounterLabel)
hide(viewCounter)
hide(shareButton)
viewCounterLabel.style.display = "none"
viewCounter.style.display = "none"
}
Expand Down Expand Up @@ -165,6 +167,17 @@ function viewPaste(content: string, views: string, singleView: boolean) {
addMessage("This is a single-view paste!")
}

if (navigator.canShare) {
show(shareButton)

shareButton.addEventListener("click", function () {
navigator.share({
title: "zer0bin paste",
url: window.location.toString(),
})
})
}

disable(saveButton)
disable(markdownButton)
enable(newButton)
Expand Down
11 changes: 11 additions & 0 deletions frontend/style/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,17 @@ a {
}
}
}
// #share-button {
// position: fixed !important;
// bottom: 0;
// left: 0;
// z-index: 10;
// color: $muted;
// &:hover {
// color: $rose;
// }
// padding: 10px;
// }
.keybind {
color: $subtle;
font-size: 11px;
Expand Down

0 comments on commit fff67c1

Please sign in to comment.