Show/remove share link if turning off Make Public

This commit is contained in:
Robbie Antenesse 2019-05-30 14:21:09 -06:00
parent 47964bcd53
commit f545f5c786
2 changed files with 11 additions and 4 deletions

View File

@ -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);
}

View File

@ -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);
}
}