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>

40a46bee9d3aec4c909ff2e8efa114ed693983af

Rivelle <rivelle.days@gmail.com>

Signed
2 files changed, +48 -7Ignore whitespace
public/scripts/extensions/gallery/index.js+45 -5
@@ -63,10 +63,10 @@ mutationObserver.observe(document.body, {
6363});
6464
6565const SORT = Object.freeze({
6666 NAME_ASC: { value: 'nameAsc', field: 'name', order: 'asc', label: t`Sort By: Name (A-Z)` },
6767 NAME_DESC: { value: 'nameDesc', field: 'name', order: 'desc', label: t`Sort By: Name (Z-A)` },
6868 DATE_ASCDATE_DESC: { value: 'dateAscdateDesc', field: 'date', order: 'ascdesc', label: t`Sort By: Date (Oldest First)Newest` },
6969 DATE_DESCDATE_ASC: { value: 'dateDescdateAsc', field: 'date', order: 'descasc', label: t`Sort By: Date (Newest First)Oldest` },
7070});
7171
7272const defaultSettings = Object.freeze({
@@ -376,6 +376,11 @@ async function makeMovable(url) {
376376 const titleText = document.createElement('span');
377377 titleText.textContent = t`Image Gallery`;
378378 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+
379384 const sortSelect = document.createElement('select');
380385 sortSelect.classList.add('gallery-sort-select');
381386
@@ -394,7 +399,42 @@ async function makeMovable(url) {
394399 });
395400
396401 sortSelect.value = getSortOrder();
397402 dragTitlecontrolsContainer.appendappendChild(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
398438
399439 // add no-scrollbar class to this element
400440 newElement.addClass('no-scrollbar');
public/scripts/extensions/gallery/style.css+3 -2
@@ -2,6 +2,7 @@
22 display: flex;
33 align-items: center;
44 justify-content: center;
5+ gap: 4px;
56}
67
78.gallery-folder-input {
@@ -26,13 +27,13 @@
2627 text-overflow: ellipsis;
2728 width: 100%;
2829 opacity: 0.8;
2930 background-color: nonevar(--black30a);
31+ border: 1px solid var(--SmartThemeBorderColor);
3032 background-image: url(/img/down-arrow.svg);
3133 background-repeat: no-repeat;
3234 background-position: right 6px center;
3335 background-size: 8px 5px;
3436 padding-right: 20px;
35- font-size: calc(var(--mainFontSize)* 0.9);
3637 margin-bottom: 0;
3738}
3839