Update public link when changing dictionaries
This commit is contained in:
parent
da2c2639b1
commit
72a7429bfa
|
@ -1,4 +1,5 @@
|
|||
import { setupLoginModal, setupChangeDictionary, setupCreateNewDictionary, setupDeletedDictionaryChangeModal, setupMakePublic } from "./setupListeners";
|
||||
import { getPublicLink } from "./utilities";
|
||||
import { request } from "./helpers";
|
||||
|
||||
export function renderLoginForm() {
|
||||
|
@ -59,14 +60,13 @@ export function renderMakePublic() {
|
|||
let waitForSync = setInterval(() => {
|
||||
if (window.currentDictionary.hasOwnProperty('externalID') && !isNaN(window.currentDictionary.externalID)) {
|
||||
clearInterval(waitForSync);
|
||||
const { externalID } = window.currentDictionary;
|
||||
const editSettingsTabHTML = `<label>Make Public
|
||||
<input type="checkbox" id="editIsPublic"${isPublic ? ' checked' : ''}><br>
|
||||
<small>Checking this box will make this public via a link you can share with others.</small>
|
||||
</label>
|
||||
<p id="publicLinkDisplay" style="${!isPublic ? 'display:none;': ''}margin-left:20px;">
|
||||
<strong>Public Link:</strong><br>
|
||||
<input readonly id="publicLink" value="${document.domain + window.location.pathname + (externalID ? externalID.toString() : '')}">
|
||||
<input readonly id="publicLink" value="${getPublicLink()}">
|
||||
<a class="small button" id="publicLinkCopy">Copy</a>
|
||||
</p>
|
||||
`;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { addMessage } from "../utilities";
|
||||
import { saveDictionary, clearDictionary } from "../dictionaryManagement";
|
||||
import { request } from "./helpers";
|
||||
import { saveToken, dictionaryIsDefault } from "./utilities";
|
||||
import { saveToken, dictionaryIsDefault, getPublicLink } from "./utilities";
|
||||
import { renderAll } from "../render";
|
||||
import { sortWords } from "../wordManagement";
|
||||
import { getLocalDeletedWords, clearLocalDeletedWords, saveDeletedWordsLocally } from "./utilities";
|
||||
|
@ -37,8 +37,14 @@ export function performSync(remoteDictionary) {
|
|||
syncWords(remoteDictionary.words, remoteDictionary.deletedWords).then(success => {
|
||||
if (success) {
|
||||
renderAll();
|
||||
|
||||
document.getElementById('accountSettingsChangeDictionary').value = window.currentDictionary.externalID;
|
||||
if (document.getElementById('publicLink')) {
|
||||
document.getElementById('publicLink').value = getPublicLink();
|
||||
}
|
||||
if (document.getElementById('publicLinkDisplay')) {
|
||||
document.getElementById('publicLinkDisplay').style.display = window.currentDictionary.settings.isPublic ? '' : 'none';
|
||||
}
|
||||
} else {
|
||||
console.error('word sync failed');
|
||||
}
|
||||
|
|
|
@ -21,6 +21,22 @@ export function dictionaryIsDefault() {
|
|||
return JSON.stringify(defaultDictionary) === JSON.stringify(currentDictionary);
|
||||
}
|
||||
|
||||
export function getPublicLink() {
|
||||
const { externalID } = window.currentDictionary;
|
||||
let path;
|
||||
if (externalID) {
|
||||
path = window.location.pathname.match(new RegExp(externalID + '$'))
|
||||
? window.location.pathname
|
||||
: (window.location.pathname.indexOf(externalID) > -1
|
||||
? window.location.pathname.substring(0, window.location.pathname.indexOf(externalID)) + externalID
|
||||
: window.location.pathname + externalID
|
||||
);
|
||||
} else {
|
||||
path = '';
|
||||
}
|
||||
return 'https://' + document.domain + path;
|
||||
}
|
||||
|
||||
export function saveDeletedWordsLocally(wordIds) {
|
||||
let storedDeletedWords = getLocalDeletedWords();
|
||||
wordIds.forEach(wordId => {
|
||||
|
|
|
@ -18,6 +18,7 @@ import { getPaginationData } from './pagination';
|
|||
import { getOpenEditForms, parseReferences } from './wordManagement';
|
||||
import { renderAd } from './ads';
|
||||
import ipaTableFile from './KeyboardFire/phondue/ipa-table.html';
|
||||
import { getPublicLink } from './account/utilities';
|
||||
|
||||
export function renderAll() {
|
||||
renderTheme();
|
||||
|
@ -54,12 +55,13 @@ export function renderName() {
|
|||
shareLink.id = 'dictionaryShare';
|
||||
shareLink.classList.add('button');
|
||||
shareLink.style.float = 'right';
|
||||
shareLink.href = window.location.pathname.match(new RegExp(window.currentDictionary.externalID + '$')) ? window.location.pathname
|
||||
: window.location.pathname.substring(0, window.location.pathname.indexOf(window.currentDictionary.externalID)) + window.currentDictionary.externalID;
|
||||
shareLink.href = getPublicLink();
|
||||
shareLink.target = '_blank';
|
||||
shareLink.title = 'Public Link to Dictionary';
|
||||
shareLink.innerHTML = '➦';
|
||||
name.parentElement.insertBefore(shareLink, name);
|
||||
} else if (isPublic && shareLinkElement) {
|
||||
shareLinkElement.href = getPublicLink();
|
||||
} else if (!isPublic && shareLinkElement) {
|
||||
shareLinkElement.parentElement.removeChild(shareLinkElement);
|
||||
}
|
||||
|
@ -193,8 +195,7 @@ export function renderWords() {
|
|||
wordId: originalWord.wordId,
|
||||
});
|
||||
const homonymnNumber = getHomonymnNumber(originalWord);
|
||||
const shareLink = window.currentDictionary.hasOwnProperty('externalID')
|
||||
? window.location.pathname + window.currentDictionary.externalID + '/' + word.wordId : '';
|
||||
const shareLink = window.currentDictionary.hasOwnProperty('externalID') ? getPublicLink() + '/' + word.wordId : '';
|
||||
|
||||
wordsHTML += renderAd(displayIndex);
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ switch ($view) {
|
|||
oldLoad && oldLoad();
|
||||
if (UpUp) {
|
||||
UpUp.start({
|
||||
'cache-version': '2.0.0',
|
||||
'cache-version': '2.0.2',
|
||||
'content-url': 'offline.html',
|
||||
'assets': [
|
||||
\"" . implode('","', $files) . "\"
|
||||
|
|
Loading…
Reference in New Issue