-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added tags of color in add url
- Loading branch information
Showing
5 changed files
with
168 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
export function RedirectToLogin() { | ||
window.location = '/logout'; | ||
window.location = '/logout'; | ||
} | ||
|
||
export function CloseModal(modalId, toClose) { | ||
const m = document.querySelector(modalId); | ||
m.addEventListener('click', () => { | ||
toClose.classList.toggle('hidden'); | ||
}); | ||
export function RefreshPage(path = '') { | ||
window.location = path; | ||
} | ||
|
||
export function CloseModal(modalId, toClose) { | ||
const m = document.querySelector(modalId); | ||
m.addEventListener('click', () => { | ||
toClose.classList.toggle('hidden'); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,96 @@ | ||
import { CloseModal } from '../common/index.js'; | ||
import {CloseModal, RefreshPage} from '../common/index.js'; | ||
|
||
const navUrl = { | ||
'/': 'home', | ||
'/home': 'home', | ||
'/archived': 'archived', | ||
'/favourite': 'favourite', | ||
'/setting': 'setting', | ||
'/trash': 'trash', | ||
'/login': 'login' | ||
'/': 'home', | ||
'/home': 'home', | ||
'/archived': 'archived', | ||
'/favourite': 'favourite', | ||
'/setting': 'setting', | ||
'/trash': 'trash', | ||
'/login': 'login' | ||
}; | ||
|
||
export function NavItemSelected() { | ||
if (!navUrl[window.location.pathname]) { | ||
return; | ||
} | ||
if (!navUrl[window.location.pathname]) { | ||
return; | ||
} | ||
|
||
const selector = window.location.pathname === '/' | ||
? document.querySelector('[data-home]') | ||
: document.querySelector(`[data-${navUrl[window.location.pathname]}]`); | ||
if (!selector) { | ||
return; | ||
} | ||
selector.classList.add('text-indigo-500'); | ||
selector.querySelector('svg').classList.add('text-indigo-500'); | ||
console.info('NavBar loaded...', navUrl[window.location.pathname]); | ||
console.info('NavBar selected item ', selector); | ||
const selector = window.location.pathname === '/' | ||
? document.querySelector('[data-home]') | ||
: document.querySelector(`[data-${navUrl[window.location.pathname]}]`); | ||
if (!selector) { | ||
return; | ||
} | ||
selector.classList.add('text-indigo-500'); | ||
selector.querySelector('svg').classList.add('text-indigo-500'); | ||
console.info('NavBar loaded...', navUrl[window.location.pathname]); | ||
console.info('NavBar selected item ', selector); | ||
} | ||
|
||
export function SideNavCollapse() { | ||
const sideNav = document.querySelector('#side-navbar'); | ||
const sideNavOpener = document.querySelector('#nav-bar-open'); | ||
if (!sideNav || !sideNavOpener) { | ||
return; | ||
} | ||
sideNavOpener.addEventListener('click', (e) => { | ||
sideNav.classList.toggle('hidden'); | ||
sideNavOpener.classList.toggle('text-indigo-500'); | ||
}); | ||
const sideNav = document.querySelector('#side-navbar'); | ||
const sideNavOpener = document.querySelector('#nav-bar-open'); | ||
if (!sideNav || !sideNavOpener) { | ||
return; | ||
} | ||
sideNavOpener.addEventListener('click', (e) => { | ||
sideNav.classList.toggle('hidden'); | ||
sideNavOpener.classList.toggle('text-indigo-500'); | ||
}); | ||
} | ||
|
||
export function AddNewWebLinkInit() { | ||
const link = document.querySelector('#add-weblink'); | ||
const linkModal = document.querySelector('#add-weblink-modal'); | ||
const saveBtn = document.querySelector('#add-link-btn'); | ||
if (!link || !linkModal || !saveBtn) { | ||
return; | ||
} | ||
link.addEventListener('click', async () => { | ||
linkModal.classList.toggle('hidden'); | ||
}); | ||
saveBtn.addEventListener('click', async () => { | ||
let url = document.querySelector('#add-weblink-input-box'); | ||
if (!url || url?.value.trim().length === 0) { | ||
return; | ||
} | ||
await AddNewLink(url?.value.trim()); | ||
linkModal.classList.toggle('hidden'); | ||
url.value = ''; | ||
}); | ||
const link = document.querySelector('#add-weblink'); | ||
const linkModal = document.querySelector('#add-weblink-modal'); | ||
const saveBtn = document.querySelector('#add-link-btn'); | ||
if (!link || !linkModal || !saveBtn) { | ||
return; | ||
} | ||
const tags = document.querySelectorAll("#tag"); | ||
let selectedTag; | ||
link.addEventListener('click', async () => { | ||
linkModal.classList.toggle('hidden'); | ||
if (tags.length) { | ||
tags.forEach((tag) => { | ||
tag.addEventListener('change', (e) => { | ||
selectedTag = e.target.value; | ||
}); | ||
}); | ||
} | ||
}); | ||
saveBtn.addEventListener('click', async () => { | ||
let url = document.querySelector('#add-weblink-input-box'); | ||
if (!url || url?.value.trim().length === 0) { | ||
return; | ||
} | ||
await AddNewLink(url?.value.trim(), selectedTag ? selectedTag : 'black'); | ||
linkModal.classList.toggle('hidden'); | ||
url.value = ''; | ||
}); | ||
|
||
CloseModal('#close-modal', linkModal); | ||
CloseModal('#close-modal', linkModal); | ||
} | ||
|
||
async function AddNewLink(webLink) { | ||
const url = '/new'; | ||
try { | ||
const headers = new Headers(); | ||
headers.append('Content-Type', 'application/json'); | ||
async function AddNewLink(webLink, selectedTag) { | ||
const url = '/new'; | ||
try { | ||
const headers = new Headers(); | ||
headers.append('Content-Type', 'application/json'); | ||
|
||
const response = await fetch(url, { | ||
method: 'POST', | ||
headers: headers, | ||
body: JSON.stringify({ url: webLink }) | ||
}); | ||
if (!response.ok) { | ||
throw new Error(`Response status: ${response.status}`); | ||
} | ||
const resp = await response.json(); | ||
if (resp?.Status === "OK") { | ||
console.info(resp?.Message); | ||
} | ||
} catch (error) { | ||
console.error(error.message); | ||
} | ||
const response = await fetch(url, { | ||
method: 'POST', | ||
headers: headers, | ||
body: JSON.stringify({url: webLink, tag: selectedTag}) | ||
}); | ||
if (!response.ok) { | ||
throw new Error(`Response status: ${response.status}`); | ||
} | ||
const resp = await response.json(); | ||
if (resp?.Status === "OK") { | ||
console.info(resp?.Message); | ||
RefreshPage(); | ||
} | ||
} catch (error) { | ||
console.error(error.message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters