- toolbar and fixes
This commit is contained in:
Jérémy Guillot
2024-06-29 14:51:10 +02:00
parent b04055ec22
commit 858a5bed06
20 changed files with 404 additions and 68 deletions

View File

@@ -0,0 +1,45 @@
// assets/controllers/dropdown_controller.js
import {Controller} from "@hotwired/stimulus"
import {useClickOutside} from "stimulus-use"
export default class extends Controller {
static targets = ["button", "menu"]
connect() {
useClickOutside(this)
}
toggle(event) {
this.menuTarget.classList.toggle('hidden')
if (!this.menuTarget.classList.contains('hidden')) {
this.positionMenu()
}
}
clickOutside(event) {
this.menuTarget.classList.add('hidden')
}
positionMenu() {
const buttonRect = this.buttonTarget.getBoundingClientRect()
const menuRect = this.menuTarget.getBoundingClientRect()
const spaceRight = window.innerWidth - buttonRect.right
const spaceBottom = window.innerHeight - buttonRect.bottom
if (spaceRight < menuRect.width && buttonRect.left > menuRect.width) {
this.menuTarget.style.left = 'auto'
this.menuTarget.style.right = '0'
} else {
this.menuTarget.style.left = '0'
this.menuTarget.style.right = 'auto'
}
if (spaceBottom < menuRect.height && buttonRect.top > menuRect.height) {
this.menuTarget.style.top = 'auto'
this.menuTarget.style.bottom = '100%'
} else {
this.menuTarget.style.top = '100%'
this.menuTarget.style.bottom = 'auto'
}
}
}

View File

@@ -0,0 +1,59 @@
// assets/controllers/toolbar_controller.js
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = ["dropdown"]
static values = {
currentSort: String,
currentOrder: String
}
refresh() {
console.log("Refreshing...")
}
syncRss() {
console.log("Syncing RSS...")
}
search() {
console.log("Searching...")
}
import() {
console.log("Importing...")
}
editMangas() {
console.log("Editing mangas...")
}
showOptions() {
console.log("Showing options...")
}
changeView() {
console.log("Changing view...")
}
sort(event) {
event.preventDefault()
const sortOption = event.currentTarget.dataset.sortOption
let order = 'asc'
if (sortOption === this.currentSortValue && this.currentOrderValue === 'asc') {
order = 'desc'
}
const url = new URL(window.location)
url.searchParams.set('sort', sortOption)
url.searchParams.set('order', order)
window.location = url.toString()
}
filter() {
console.log("Filtering...")
}
}