Bare URL selector now saves to localStorage.

This commit is contained in:
wearrrrr 2024-01-18 13:54:40 -06:00
parent 3024ce1554
commit 8b20308a83
3 changed files with 41 additions and 12 deletions

View file

@ -1,5 +1,4 @@
--- ---
// TODO: Add Props to make this component more dynamic!!
const { buttonNameDefault, dropdownList, id } = Astro.props; const { buttonNameDefault, dropdownList, id } = Astro.props;
--- ---

View file

@ -1,7 +1,29 @@
--- ---
const { type } = Astro.props; const { type, inputName, defaultTextContent } = Astro.props;
// as any should not be necessary here... but it is womp womp.
interface Props {
type?: string;
inputName: string;
defaultTextContent?: string;
}
--- ---
<div class="input-container"> <div class="input-container">
<input type={type || "input"}> <input id={inputName + "-input"} type={type as any} />
</div> </div>
<style>
input {
height: 43px;
width: 100%;
border: 4px solid #E0E0E0;
border-radius: 10px;
background-color: #1b1b1b;
color: white;
transition: 100ms ease-in-out;
}
input:focus {
outline: none;
border: 4px solid #7900e1;
}
</style>

View file

@ -21,7 +21,7 @@ import Input from "./Input.astro";
</div> </div>
<div class="setting__bare-url"> <div class="setting__bare-url">
<p class="setting-label">Bare URL</p> <p class="setting-label">Bare URL</p>
<Input /> <Input inputName="bare-url" defaultTextContent="/bare/" />
</div> </div>
</div> </div>
</div> </div>
@ -140,7 +140,7 @@ import Input from "./Input.astro";
} }
} }
function applyEventListeners(item, dropdownID, localStorageItem) { function applyDropdownEventListeners(item, dropdownID, localStorageItem) {
Array.from(item.children).forEach((item) => { Array.from(item.children).forEach((item) => {
item.addEventListener('click', () => { item.addEventListener('click', () => {
localStorage.setItem(localStorageItem, item.dataset.setting) localStorage.setItem(localStorageItem, item.dataset.setting)
@ -154,7 +154,7 @@ import Input from "./Input.astro";
loadContent('setting-tab-proxy') loadContent('setting-tab-proxy')
function setLocalStorageItem(event) { function setupSettings(event) {
if (event.detail == "setting-tab-proxy") { if (event.detail == "setting-tab-proxy") {
applySavedLocalStorage('selectedProxy', 'dropdown__selected-proxy'); applySavedLocalStorage('selectedProxy', 'dropdown__selected-proxy');
applySavedLocalStorage('selectedSearchEngine', 'dropdown__search-engine'); applySavedLocalStorage('selectedSearchEngine', 'dropdown__search-engine');
@ -162,15 +162,23 @@ import Input from "./Input.astro";
let selectedProxyDropdown = document.getElementById('dropdown__selected-proxy-menu') let selectedProxyDropdown = document.getElementById('dropdown__selected-proxy-menu')
let searchEngineDropdown = document.getElementById('dropdown__search-engine-menu') let searchEngineDropdown = document.getElementById('dropdown__search-engine-menu')
let openWithDropdown = document.getElementById('dropdown__open-with-menu') let openWithDropdown = document.getElementById('dropdown__open-with-menu')
applyEventListeners(searchEngineDropdown, 'dropdown__search-engine', 'selectedSearchEngine'); let bareUrlInput = document.getElementById('bare-url-input')
applyEventListeners(selectedProxyDropdown, 'dropdown__selected-proxy', 'selectedProxy'); bareUrlInput.addEventListener('change', () => {
applyEventListeners(openWithDropdown, 'dropdown__open-with', 'selectedOpenWith'); localStorage.setItem('bareUrl', bareUrlInput.value)
})
applyDropdownEventListeners(searchEngineDropdown, 'dropdown__search-engine', 'selectedSearchEngine');
applyDropdownEventListeners(selectedProxyDropdown, 'dropdown__selected-proxy', 'selectedProxy');
applyDropdownEventListeners(openWithDropdown, 'dropdown__open-with', 'selectedOpenWith');
if (localStorage.getItem('bareUrl')) {
bareUrlInput.value = localStorage.getItem('bareUrl')
} else {
bareUrlInput.value = '/bare/'
}
} }
} }
document.addEventListener('setting-tabLoad', setLocalStorageItem) document.addEventListener('setting-tabLoad', setupSettings)
</script> </script>
<style> <style>
.content-hidden { .content-hidden {