settings page, clipboard component

This commit is contained in:
realaravinth
2021-07-20 18:14:23 +05:30
parent db941d51b7
commit 4b18992f6a
23 changed files with 375 additions and 99 deletions

View File

@@ -18,6 +18,7 @@
@import '../../../../reset';
@import '../../../../vars';
@import '../../../../components/box';
@import '../../../../components/clipboard/copy';
@import '../../../../components/table/main';
.sitekey__table {
@@ -37,26 +38,17 @@
width: 10px;
}
@mixin copy-icon-base {
margin: auto;
padding: 5px;
}
.sitekey__copy-icon {
@include copy-icon-base;
@include copy-icon;
}
.sitekey__copy-icon:hover {
cursor: pointer;
filter: invert(17%) sepia(93%) saturate(5039%) hue-rotate(204deg)
brightness(100%) contrast(98%);
.sitekey__copy-icon:hover,
.sitekey__copy-done-icon:hover {
@include copy-icon-hover;
}
.sitekey__copy-done-icon {
@include copy-icon-base;
display: none;
filter: invert(58%) sepia(60%) saturate(331%) hue-rotate(76deg)
brightness(91%) contrast(92%);
@include copy-done-icon;
}
.sitekey__key-container {

View File

@@ -1,3 +1,8 @@
<. const DONE_ALT: &str = "sitekey copied"; .>
<. const DONE_CLASS: &str = "sitekey__copy-done-icon"; .>
<. const COPY_ALT: &str = "copy sitekey"; .>
<. const COPY_CLASS: &str = "sitekey__copy-icon"; .>
<. include!("../../../components/headers/index.html"); .> <.
include!("../../navbar/index.html"); .>
<div class="tmp-layout">
@@ -28,12 +33,8 @@ include!("../../navbar/index.html"); .>
</td>
<td class="sitekey-list__key">
<div class="sitekey__key-container">
<img class="sitekey__copy-icon" src="<.= crate::FILES
.get("./static/cache/img/svg/clipboard.svg") .unwrap() .>"
alt="copy sitekey" data-sitekey="<.= sitekey.key .>" /> <img
class="sitekey__copy-done-icon" src="<.= crate::FILES
.get("./static/cache/img/svg/check.svg") .unwrap() .>"
alt="sitekey copied" data-sitekey="<.= sitekey.key .>" />
<. let clipboard_data = ("sitekey", &sitekey.key); .>
<. include!("../../../components/clipboard/index.html"); .>
<a
class="sitekey__widget-link"
href="<.= crate::WIDGET_ROUTES.verification_widget .>/?sitekey=<.= sitekey.key .>"
@@ -43,10 +44,10 @@ include!("../../navbar/index.html"); .>
</div>
</td>
<td class="sitekey-list__key">
<div class="sitekey-list__edit">
<. let key = format!("/sitekey/{}", &sitekey.key); .>
<. include!("../view/__edit-sitekey-icon.html"); .>
</div>
<div class="sitekey-list__edit">
<. let key = format!("/sitekey/{}", &sitekey.key); .>
<. include!("../view/__edit-sitekey-icon.html"); .>
</div>
</td>
</tr>
<. } .>

View File

@@ -14,40 +14,19 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
export const index = () => {
registerCopySitekey();
};
import CopyIcon from '../../../../components/clipboard/';
const SITEKEY_COPY_ICON = `sitekey__copy-icon`;
const SITEKEY_COPY_DONE_ICON = `sitekey__copy-done-icon`;
const registerCopySitekey = () => {
const icons = document.querySelectorAll(`.${SITEKEY_COPY_ICON}`);
icons.forEach(icon => {
icon.addEventListener('click', e => copySitekey(e));
});
};
/*
* Copy sitekey to clipboard
*/
const copySitekey = async (e: Event) => {
const image = <HTMLElement>e.target;
export const index = () => {
const image = <HTMLElement>document.querySelector(`.${SITEKEY_COPY_ICON}`);
if (!image.classList.contains(SITEKEY_COPY_ICON)) {
throw new Error(
'This method should only be called when sitekey copy button/icon is clicked',
);
}
const copyDoneIcon = <HTMLElement>(
image.parentElement.querySelector(`.${SITEKEY_COPY_DONE_ICON}`)
);
const sitekey = image.dataset.sitekey;
await navigator.clipboard.writeText(sitekey);
image.style.display = 'none';
copyDoneIcon.style.display = 'block';
setTimeout(() => {
copyDoneIcon.style.display = 'none';
image.style.display = 'block';
}, 1200);
new CopyIcon(sitekey, SITEKEY_COPY_ICON, SITEKEY_COPY_DONE_ICON);
};