diff --git a/resources/js/components/SMEditor.vue b/resources/js/components/SMEditor.vue index 76a83a6..2134783 100644 --- a/resources/js/components/SMEditor.vue +++ b/resources/js/components/SMEditor.vue @@ -249,6 +249,8 @@ const imageBrowser = (callback, value, meta) => { var libraryPage = 1; var libraryMax = 1; var selected = value; + var title = ""; + var itemsFound = 0; console.log(selected); @@ -289,6 +291,17 @@ const imageBrowser = (callback, value, meta) => { const updateLibrary = () => { const limit = 24; + const searchFunc = function () { + title = ( + document.getElementById( + "image-library-search-input" + ) as HTMLInputElement + ).value; + + updateLibrary(); + console.log("here"); + }; + document.getElementById("image-library-pagination-current").innerHTML = libraryPage.toString(); @@ -308,22 +321,40 @@ const imageBrowser = (callback, value, meta) => { } }; + document.getElementById("image-library-search-button").onclick = + searchFunc; + document.getElementById("image-library-search-input").onkeydown = + function (event) { + if (event.key === "Enter") { + searchFunc(); + } + }; + + console.log(title); api.get({ url: "/media", params: { limit: limit, page: libraryPage, mime: "image/", + title: title, }, }) .then((result) => { const data = result.data as MediaCollection; libraryMax = Math.ceil(data.total / limit); + itemsFound = data.total; document.getElementById( "image-library-pagination-max" ).innerHTML = libraryMax.toString(); + document.getElementById( + "image-library-item-count" + ).innerHTML = `${itemsFound.toString()} image${ + itemsFound == 1 ? "" : "s" + } found`; + const libraryContainer = document.getElementById( "image-library-content" ); @@ -337,35 +368,43 @@ const imageBrowser = (callback, value, meta) => { // add new items data.media.forEach((medium) => { - const img = document.createElement("div"); - img.classList.add("image-library-content-image"); + const item = document.createElement("div"); + item.classList.add("image-library-content-item"); if (urlMatches(medium.url, selected)) { - img.classList.add( - "image-library-content-image-selected" + item.classList.add( + "image-library-content-item-selected" ); } - img.style.backgroundImage = `url('${medium.url}?w=200')`; - img.style.cursor = "pointer"; - img.onclick = function () { - // Remove the "image-library-content-image-selected" class from all the image elements - const images = libraryContainer.querySelectorAll( - ".image-library-content-image" + + item.onclick = function () { + const items = libraryContainer.querySelectorAll( + ".image-library-content-item" ); - images.forEach((image) => { - image.classList.remove( - "image-library-content-image-selected" + items.forEach((item) => { + item.classList.remove( + "image-library-content-item-selected" ); }); - // Add the "image-library-content-image-selected" class to the clicked image element - img.classList.add( - "image-library-content-image-selected" + item.classList.add( + "image-library-content-item-selected" ); selected = medium.url; }; - libraryContainer.appendChild(img); + const image = document.createElement("div"); + image.classList.add("image-library-content-item-image"); + image.style.backgroundImage = `url('${medium.url}?w=200')`; + + const title = document.createElement("div"); + title.classList.add("image-library-content-item-title"); + title.innerHTML = medium.title; + + item.appendChild(image); + item.appendChild(title); + + libraryContainer.appendChild(item); }); } }) @@ -403,7 +442,7 @@ const imageBrowser = (callback, value, meta) => {