From 918dad1ad88d9940103fe9837cfce50e0cd7465e Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Thu, 30 May 2019 14:21:09 -0600 Subject: [PATCH] Show/remove share link if turning off Make Public --- src/js/dictionaryManagement.js | 9 ++++++--- src/js/render.js | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/js/dictionaryManagement.js b/src/js/dictionaryManagement.js index 78d0338..cce0358 100644 --- a/src/js/dictionaryManagement.js +++ b/src/js/dictionaryManagement.js @@ -1,4 +1,4 @@ -import { renderDictionaryDetails, renderPartsOfSpeech, renderAll } from "./render"; +import { renderDictionaryDetails, renderPartsOfSpeech, renderAll, renderWords } from "./render"; import { removeTags, cloneObject, getTimestampInSeconds, download, slugify } from "../helpers"; import { LOCAL_STORAGE_KEY, DEFAULT_DICTIONARY, MIGRATE_VERSION } from "../constants"; import { addMessage, getNextId, hasToken } from "./utilities"; @@ -63,7 +63,10 @@ export function saveEditModal() { window.currentDictionary.settings.caseSensitive = document.getElementById('editCaseSensitive').checked; const needsReSort = window.currentDictionary.settings.sortByDefinition !== document.getElementById('editSortByDefinition').checked; window.currentDictionary.settings.sortByDefinition = document.getElementById('editSortByDefinition').checked; + + let needsWordRender = false; if (hasToken()) { + needsWordRender = window.currentDictionary.settings.isPublic !== document.getElementById('editIsPublic').checked; window.currentDictionary.settings.isPublic = document.getElementById('editIsPublic').checked; } else { window.currentDictionary.settings.isPublic = false; @@ -73,8 +76,8 @@ export function saveEditModal() { saveDictionary(); renderDictionaryDetails(); renderPartsOfSpeech(); - - if (needsReSort) { + + if (needsReSort || needsWordRender) { sortWords(true); } diff --git a/src/js/render.js b/src/js/render.js index ca79c1c..d8710fd 100644 --- a/src/js/render.js +++ b/src/js/render.js @@ -39,7 +39,9 @@ export function renderName() { const name = document.getElementById('dictionaryName'); name.innerHTML = dictionaryName; const isPublic = hasToken() && window.currentDictionary.settings.isPublic; - if (isPublic && !document.getElementById('dictionaryShare')) { + const shareLinkElement = document.getElementById('dictionaryShare'); + + if (isPublic && !shareLinkElement) { const shareLink = document.createElement('a'); shareLink.id = 'dictionaryShare'; shareLink.classList.add('button'); @@ -50,6 +52,8 @@ export function renderName() { shareLink.title = 'Public Link to Dictionary'; shareLink.innerHTML = '➦'; name.parentElement.insertBefore(shareLink, name); + } else if (!isPublic && shareLinkElement) { + shareLinkElement.parentElement.removeChild(shareLinkElement); } }