diff --git a/src/js/account/render.js b/src/js/account/render.js index 38f2d92..d391e63 100644 --- a/src/js/account/render.js +++ b/src/js/account/render.js @@ -1,4 +1,4 @@ -import { setupLoginModal, setupChangeDictionary, setupCreateNewDictionary, setupDeletedDictionaryChangeModal } from "./setupListeners"; +import { setupLoginModal, setupChangeDictionary, setupCreateNewDictionary, setupDeletedDictionaryChangeModal, setupMakePublic } from "./setupListeners"; import { request } from "./helpers"; export function renderLoginForm() { @@ -55,12 +55,20 @@ export function renderLoginForm() { export function renderMakePublic() { const editSettingsTab = document.getElementById('editSettingsTab'); + const { isPublic } = window.currentDictionary.settings; const editSettingsTabHTML = ` +

+ Public Link:
+ + Copy +

`; editSettingsTab.innerHTML += editSettingsTabHTML; + + setupMakePublic(); } export function renderAccountSettings() { diff --git a/src/js/account/setupListeners.js b/src/js/account/setupListeners.js index 60670d4..b3bf316 100644 --- a/src/js/account/setupListeners.js +++ b/src/js/account/setupListeners.js @@ -1,6 +1,7 @@ import { logIn, createAccount } from "./login"; import { setCookie } from "../StackOverflow/cookie"; import { changeDictionary, createNewDictionary } from "./dictionaryManagement"; +import { addMessage } from "../utilities"; export function setupLoginModal(modal) { const closeElements = modal.querySelectorAll('.modal-background, .close-button'); @@ -60,3 +61,14 @@ export function setupDeletedDictionaryChangeModal() { } document.getElementById('createNewDictionaryAfterDelete').addEventListener('click', createNewDictionary); } + +export function setupMakePublic() { + document.getElementById('editIsPublic').addEventListener('change', function(event) { + document.getElementById('publicLinkDisplay').style.display = event.target.checked ? '' : 'none'; + }); + document.getElementById('publicLinkCopy').addEventListener('click', function() { + document.getElementById('publicLink').select(); + document.execCommand('copy'); + addMessage('Copied public link to clipboard', 3000); + }); +}