Show/remove share link if turning off Make Public

This commit is contained in:
Robbie Antenesse 2019-05-30 14:21:09 -06:00 committed by Robbie Antenesse
parent 596efff70d
commit db021647bd
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;
@ -74,7 +77,7 @@ export function saveEditModal() {
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);
}
}