refactoring: update severals components
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import { loadState } from '@nextcloud/initial-state'
|
||||
|
||||
const getActiveAppId = () => {
|
||||
const apps = loadState('core', 'apps', {})
|
||||
|
||||
for (let id in apps) {
|
||||
if (apps[id].active) {
|
||||
return id
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export { getActiveAppId }
|
||||
@@ -1,4 +1,16 @@
|
||||
module.exports = (tagName, attributes) => {
|
||||
const waitContainer = async (selector) => {
|
||||
new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
const container = document.querySelector(selector)
|
||||
|
||||
if (container) {
|
||||
resolve(selector, container)
|
||||
}
|
||||
}, 50)
|
||||
})
|
||||
}
|
||||
|
||||
const createElement = (tagName, attributes) => {
|
||||
const element = document.createElement(tagName)
|
||||
|
||||
if (typeof attributes === 'object') {
|
||||
@@ -15,3 +27,5 @@ module.exports = (tagName, attributes) => {
|
||||
|
||||
return element
|
||||
}
|
||||
|
||||
export { waitContainer, createElement }
|
||||
@@ -0,0 +1,26 @@
|
||||
const containsAppsMatchingSearch = (values, search) => {
|
||||
if (search.value.trim() === '') {
|
||||
return true
|
||||
}
|
||||
|
||||
for (let key in values) {
|
||||
if (isAppMatchingSearch(values[key].name)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
const isAppMatchingSearch = (item, search) => {
|
||||
if (search.value.trim() === '') {
|
||||
return true
|
||||
}
|
||||
|
||||
return item.name.toLowerCase().includes(search.value.trim().toLowerCase())
|
||||
}
|
||||
|
||||
export {
|
||||
containsAppsMatchingSearch,
|
||||
isAppMatchingSearch,
|
||||
}
|
||||
Reference in New Issue
Block a user