Improvement: Add Upload Button to Image Gallery (#4500) * Improvement: Add Upload Button to Image Gallery - Added an **Upload Image** button to the **Image Gallery** for a more intuitive experience and easier use on mobile devices ~~(so I can upload some awesome GIFs right from my phone)~~ - Adjusted the `<select class="gallery-sort-select">` menu styling for better consistency with other sections, making it more compact and reducing wasted space * Fix type error --------- Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
Signed| @@ -63,10 +63,10 @@ mutationObserver.observe(document.body, { | |||
| 63 | }); | 63 | }); |
| 64 | 64 | ||
| 65 | const SORT = Object.freeze({ | 65 | const SORT = Object.freeze({ |
| 66 | NAME_ASC: { value: 'nameAsc', field: 'name', order: 'asc', label: t`Sort By: Name (A-Z)` }, | 66 | NAME_ASC: { value: 'nameAsc', field: 'name', order: 'asc', label: t`Name (A-Z)` }, |
| 67 | NAME_DESC: { value: 'nameDesc', field: 'name', order: 'desc', label: t`Sort By: Name (Z-A)` }, | 67 | NAME_DESC: { value: 'nameDesc', field: 'name', order: 'desc', label: t`Name (Z-A)` }, |
| 68 | DATE_ASC: { value: 'dateAsc', field: 'date', order: 'asc', label: t`Sort By: Date (Oldest First)` }, | 68 | DATE_DESC: { value: 'dateDesc', field: 'date', order: 'desc', label: t`Newest` }, |
| 69 | DATE_DESC: { value: 'dateDesc', field: 'date', order: 'desc', label: t`Sort By: Date (Newest First)` }, | 69 | DATE_ASC: { value: 'dateAsc', field: 'date', order: 'asc', label: t`Oldest` }, |
| 70 | }); | 70 | }); |
| 71 | 71 | ||
| 72 | const defaultSettings = Object.freeze({ | 72 | const defaultSettings = Object.freeze({ |
| @@ -376,6 +376,11 @@ async function makeMovable(url) { | |||
| 376 | const titleText = document.createElement('span'); | 376 | const titleText = document.createElement('span'); |
| 377 | titleText.textContent = t`Image Gallery`; | 377 | titleText.textContent = t`Image Gallery`; |
| 378 | dragTitle.append(titleText); | 378 | dragTitle.append(titleText); |
| 379 | |||
| 380 | // Create a container for the controls | ||
| 381 | const controlsContainer = document.createElement('div'); | ||
| 382 | controlsContainer.classList.add('flex-container', 'alignItemsCenter'); | ||
| 383 | |||
| 379 | const sortSelect = document.createElement('select'); | 384 | const sortSelect = document.createElement('select'); |
| 380 | sortSelect.classList.add('gallery-sort-select'); | 385 | sortSelect.classList.add('gallery-sort-select'); |
| 381 | 386 | ||
| @@ -394,7 +399,42 @@ async function makeMovable(url) { | |||
| 394 | }); | 399 | }); |
| 395 | 400 | ||
| 396 | sortSelect.value = getSortOrder(); | 401 | sortSelect.value = getSortOrder(); |
| 397 | dragTitle.append(sortSelect); | 402 | controlsContainer.appendChild(sortSelect); |
| 403 | |||
| 404 | // Create the "Add Image" button | ||
| 405 | const addImageButton = document.createElement('div'); | ||
| 406 | addImageButton.classList.add('menu_button', 'menu_button_icon', 'interactable'); | ||
| 407 | addImageButton.title = 'Add Image'; | ||
| 408 | addImageButton.innerHTML = '<i class="fa-solid fa-plus fa-fw"></i><div>Add Image</div>'; | ||
| 409 | |||
| 410 | // Create a hidden file input | ||
| 411 | const fileInput = document.createElement('input'); | ||
| 412 | fileInput.type = 'file'; | ||
| 413 | fileInput.accept = 'image/*'; | ||
| 414 | fileInput.multiple = true; | ||
| 415 | fileInput.style.display = 'none'; | ||
| 416 | |||
| 417 | // Trigger file input when the button is clicked | ||
| 418 | addImageButton.addEventListener('click', () => { | ||
| 419 | fileInput.click(); | ||
| 420 | }); | ||
| 421 | |||
| 422 | // Handle file selection | ||
| 423 | fileInput.addEventListener('change', async () => { | ||
| 424 | const files = fileInput.files; | ||
| 425 | if (files.length > 0) { | ||
| 426 | for (const file of files) { | ||
| 427 | await uploadFile(file, url); | ||
| 428 | } | ||
| 429 | // Refresh the gallery | ||
| 430 | closeButton.trigger('click'); | ||
| 431 | await showCharGallery(); | ||
| 432 | } | ||
| 433 | }); | ||
| 434 | |||
| 435 | controlsContainer.appendChild(addImageButton); | ||
| 436 | dragTitle.append(controlsContainer); | ||
| 437 | newElement.append(fileInput); // Append hidden file input to the main element | ||
| 398 | 438 | ||
| 399 | // add no-scrollbar class to this element | 439 | // add no-scrollbar class to this element |
| 400 | newElement.addClass('no-scrollbar'); | 440 | newElement.addClass('no-scrollbar'); |
| @@ -2,6 +2,7 @@ | |||
| 2 | display: flex; | 2 | display: flex; |
| 3 | align-items: center; | 3 | align-items: center; |
| 4 | justify-content: center; | 4 | justify-content: center; |
| 5 | gap: 4px; | ||
| 5 | } | 6 | } |
| 6 | 7 | ||
| 7 | .gallery-folder-input { | 8 | .gallery-folder-input { |
| @@ -26,13 +27,13 @@ | |||
| 26 | text-overflow: ellipsis; | 27 | text-overflow: ellipsis; |
| 27 | width: 100%; | 28 | width: 100%; |
| 28 | opacity: 0.8; | 29 | opacity: 0.8; |
| 29 | background: none; | 30 | background-color: var(--black30a); |
| 31 | border: 1px solid var(--SmartThemeBorderColor); | ||
| 30 | background-image: url(/img/down-arrow.svg); | 32 | background-image: url(/img/down-arrow.svg); |
| 31 | background-repeat: no-repeat; | 33 | background-repeat: no-repeat; |
| 32 | background-position: right 6px center; | 34 | background-position: right 6px center; |
| 33 | background-size: 8px 5px; | 35 | background-size: 8px 5px; |
| 34 | padding-right: 20px; | 36 | padding-right: 20px; |
| 35 | font-size: calc(var(--mainFontSize)* 0.9); | ||
| 36 | margin-bottom: 0; | 37 | margin-bottom: 0; |
| 37 | } | 38 | } |
| 38 | 39 | ||