Use const instead of let when possible
This commit is contained in:
parent
ffc8a13db6
commit
cdb79d11aa
|
@ -27,7 +27,7 @@ Rectangle {
|
|||
|
||||
function enterClickButton() {
|
||||
for (let i = 0; i < buttonModel.length; i++) {
|
||||
let btn = buttonRepeater.itemAt(i)
|
||||
const btn = buttonRepeater.itemAt(i)
|
||||
if (btn.enabled && btn.name === clickButtonOnEnter) btn.clicked()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ Menu {
|
|||
let result = 0
|
||||
|
||||
for (let i = 0; i < count; ++i) {
|
||||
let item = itemAt(i)
|
||||
const item = itemAt(i)
|
||||
if (! item.visible) continue
|
||||
|
||||
result = Math.max(item.implicitWidth, result)
|
||||
|
|
|
@ -25,8 +25,8 @@ HImage {
|
|||
function update() {
|
||||
if (! py) return // component was destroyed
|
||||
|
||||
let w = sourceSize.width || width
|
||||
let h = sourceSize.height || height
|
||||
const w = sourceSize.width || width
|
||||
const h = sourceSize.height || height
|
||||
|
||||
if (! image.mxc || w < 1 || h < 1 ) {
|
||||
show = false
|
||||
|
@ -39,9 +39,9 @@ HImage {
|
|||
return
|
||||
}
|
||||
|
||||
let method = image.thumbnail ? "get_thumbnail" : "get_media"
|
||||
let args = image.thumbnail ?
|
||||
[image.mxc, w, h, cryptDict] : [image.mxc, cryptDict]
|
||||
const method = image.thumbnail ? "get_thumbnail" : "get_media"
|
||||
const args = image.thumbnail ?
|
||||
[image.mxc, w, h, cryptDict] : [image.mxc, cryptDict]
|
||||
|
||||
py.callCoro("media_cache." + method, args, path => {
|
||||
if (! image) return
|
||||
|
|
|
@ -25,9 +25,9 @@ FocusScope {
|
|||
]
|
||||
|
||||
readonly property string joinedSelection: {
|
||||
let toCopy = []
|
||||
const toCopy = []
|
||||
|
||||
for (let key of Object.keys(selectedTexts).sort()) {
|
||||
for (const key of Object.keys(selectedTexts).sort()) {
|
||||
if (! selectedTexts[key]) continue
|
||||
|
||||
// For some dumb reason, Object.keys convert the floats to strings
|
||||
|
@ -53,7 +53,7 @@ FocusScope {
|
|||
selecting = false
|
||||
}
|
||||
onDragPointChanged: {
|
||||
let pos = mapFromItem(
|
||||
const pos = mapFromItem(
|
||||
mainUI, eventPoint.scenePosition.x, eventPoint.scenePosition.y,
|
||||
)
|
||||
draggedItem.x = pos.x
|
||||
|
|
|
@ -26,7 +26,7 @@ HFileDialogOpener {
|
|||
function exportKeys(file, passphrase) {
|
||||
exporting = true
|
||||
|
||||
let path = file.toString().replace(/^file:\/\//, "")
|
||||
const path = file.toString().replace(/^file:\/\//, "")
|
||||
|
||||
py.callClientCoro(userId, "export_keys", [path, passphrase], () => {
|
||||
exporting = false
|
||||
|
|
|
@ -29,8 +29,8 @@ HFileDialogOpener {
|
|||
|
||||
|
||||
function verifyPassword(pass, callback) {
|
||||
importing = true
|
||||
let path = file.toString().replace(/^file:\/\//, "")
|
||||
importing = true
|
||||
const path = file.toString().replace(/^file:\/\//, "")
|
||||
|
||||
py.callClientCoro(userId, "import_keys", [path, pass], () => {
|
||||
importing = false
|
||||
|
|
|
@ -9,8 +9,8 @@ HFileDialogOpener {
|
|||
dialog.fileMode: FileDialog.OpenFiles
|
||||
|
||||
onFilesPicked: {
|
||||
for (let file of files) {
|
||||
let path = Qt.resolvedUrl(file).replace(/^file:/, "")
|
||||
for (const file of files) {
|
||||
const path = Qt.resolvedUrl(file).replace(/^file:/, "")
|
||||
|
||||
utils.sendFile(userId, roomId, path, () => {
|
||||
if (destroyWhenDone) destroy()
|
||||
|
|
|
@ -73,14 +73,14 @@ HListView {
|
|||
}
|
||||
|
||||
function _previous() {
|
||||
let currentAccount = currentItem
|
||||
const currentAccount = currentItem
|
||||
|
||||
// Nothing is selected
|
||||
if (! currentAccount) {
|
||||
decrementCurrentIndex()
|
||||
}
|
||||
|
||||
let roomList = currentAccount.roomList
|
||||
const roomList = currentAccount.roomList
|
||||
|
||||
// An account is selected
|
||||
if (! roomList.currentItem) {
|
||||
|
|
|
@ -20,8 +20,8 @@ HLoader {
|
|||
return
|
||||
}
|
||||
|
||||
let page = window.uiState.page
|
||||
let props = window.uiState.pageProperties
|
||||
const page = window.uiState.page
|
||||
const props = window.uiState.pageProperties
|
||||
|
||||
if (page === "Pages/Chat/Chat.qml") {
|
||||
pageLoader.showRoom(props.userId, props.roomId)
|
||||
|
@ -46,7 +46,7 @@ HLoader {
|
|||
}
|
||||
|
||||
function showPage(name, properties={}) {
|
||||
let path = `Pages/${name}.qml`
|
||||
const path = `Pages/${name}.qml`
|
||||
_show(path, properties)
|
||||
|
||||
window.uiState.page = path
|
||||
|
@ -66,7 +66,7 @@ HLoader {
|
|||
timesBack = Math.min(timesBack, history.length - 1)
|
||||
if (timesBack < 1) return false
|
||||
|
||||
let [componentUrl, properties] = history[timesBack]
|
||||
const [componentUrl, properties] = history[timesBack]
|
||||
|
||||
_show(componentUrl, properties)
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ HGridLayout {
|
|||
if (avatar.changed) {
|
||||
saveButton.avatarChangeRunning = true
|
||||
|
||||
let path =
|
||||
const path =
|
||||
Qt.resolvedUrl(avatar.sourceOverride).replace(/^file:/, "")
|
||||
|
||||
py.callClientCoro(userId, "set_avatar_from_file", [path], () => {
|
||||
|
|
|
@ -30,7 +30,7 @@ HBox {
|
|||
|
||||
errorMessage.text = ""
|
||||
|
||||
let args = [
|
||||
const args = [
|
||||
idField.text.trim(), passwordField.text,
|
||||
undefined, serverField.text.trim(),
|
||||
]
|
||||
|
|
|
@ -20,7 +20,7 @@ HBox {
|
|||
button.loading = true
|
||||
errorMessage.text = ""
|
||||
|
||||
let args = [
|
||||
const args = [
|
||||
nameField.text,
|
||||
topicField.text,
|
||||
publicCheckBox.checked,
|
||||
|
|
|
@ -25,7 +25,7 @@ HBox {
|
|||
button.loading = true
|
||||
errorMessage.text = ""
|
||||
|
||||
let args = [userField.text.trim(), encryptCheckBox.checked]
|
||||
const args = [userField.text.trim(), encryptCheckBox.checked]
|
||||
|
||||
py.callClientCoro(userId, "new_direct_chat", args, roomId => {
|
||||
button.loading = false
|
||||
|
|
|
@ -25,7 +25,7 @@ HBox {
|
|||
button.loading = true
|
||||
errorMessage.text = ""
|
||||
|
||||
let args = [roomField.text.trim()]
|
||||
const args = [roomField.text.trim()]
|
||||
|
||||
py.callClientCoro(userId, "room_join", args, roomId => {
|
||||
button.loading = false
|
||||
|
|
|
@ -101,7 +101,7 @@ Rectangle {
|
|||
|
||||
let foundAlias = null
|
||||
|
||||
for (let [user, writing_alias] of Object.entries(aliases)) {
|
||||
for (const [user, writing_alias] of Object.entries(aliases)) {
|
||||
if (text.startsWith(writing_alias + " ")) {
|
||||
writingUserId = user
|
||||
foundAlias = new RegExp("^" + writing_alias + " ")
|
||||
|
@ -119,15 +119,15 @@ Rectangle {
|
|||
writingUserId = Qt.binding(() => chat.userId)
|
||||
toSend = text
|
||||
|
||||
let vals = Object.values(aliases)
|
||||
const vals = Object.values(aliases)
|
||||
|
||||
let longestAlias =
|
||||
const longestAlias =
|
||||
vals.reduce((a, b) => a.length > b.length ? a: b)
|
||||
|
||||
let textNotStartsWithAnyAlias =
|
||||
const textNotStartsWithAnyAlias =
|
||||
! vals.some(a => a.startsWith(text))
|
||||
|
||||
let textContainsCharNotInAnyAlias =
|
||||
const textContainsCharNotInAnyAlias =
|
||||
vals.every(a => text.split("").some(c => ! a.includes(c)))
|
||||
|
||||
// Only set typing when it's sure that the user will not use
|
||||
|
@ -162,21 +162,21 @@ Rectangle {
|
|||
ev.modifiers & Qt.AltModifier)
|
||||
{
|
||||
let indents = 0
|
||||
let parts = lineText.split(indent)
|
||||
const parts = lineText.split(indent)
|
||||
|
||||
for (const [i, part] of parts.entries()) {
|
||||
if (i === parts.length - 1 || part) { break }
|
||||
indents += 1
|
||||
}
|
||||
|
||||
let add = indent.repeat(indents)
|
||||
const add = indent.repeat(indents)
|
||||
textArea.insert(cursorPosition, "\n" + add)
|
||||
return
|
||||
}
|
||||
|
||||
if (textArea.text === "") { return }
|
||||
|
||||
let args = [chat.roomId, toSend]
|
||||
const args = [chat.roomId, toSend]
|
||||
py.callClientCoro(writingUserId, "send_text", args)
|
||||
|
||||
area.clear()
|
||||
|
|
|
@ -71,8 +71,8 @@ HMxcImage {
|
|||
return
|
||||
}
|
||||
|
||||
let toOpen = loader.mediaUrl || loader.thumbnailMxc
|
||||
let isMxc = toOpen.startsWith("mxc://")
|
||||
const toOpen = loader.mediaUrl || loader.thumbnailMxc
|
||||
const isMxc = toOpen.startsWith("mxc://")
|
||||
|
||||
isMxc ?
|
||||
py.callClientCoro(chat.userId, "mxc_to_http", [toOpen], callback) :
|
||||
|
|
|
@ -20,11 +20,11 @@ Rectangle {
|
|||
target: null
|
||||
onActiveChanged: if (! active) dragFlicker.speed = 0
|
||||
onCentroidChanged: {
|
||||
let left = centroid.pressedButtons & Qt.LeftButton
|
||||
let vel = centroid.velocity.y
|
||||
let pos = centroid.position.y
|
||||
let dist = Math.min(selectableLabelContainer.height / 4, 50)
|
||||
let boost = 20 * (pos < dist ? -pos : -(height - pos))
|
||||
const left = centroid.pressedButtons & Qt.LeftButton
|
||||
const vel = centroid.velocity.y
|
||||
const pos = centroid.position.y
|
||||
const dist = Math.min(selectableLabelContainer.height / 4, 50)
|
||||
const boost = 20 * (pos < dist ? -pos : -(height - pos))
|
||||
|
||||
dragFlicker.speed =
|
||||
left && vel && pos < dist ? 1000 + boost :
|
||||
|
|
|
@ -47,19 +47,19 @@ HLoader {
|
|||
if (singleMediaInfo.event_type === "RoomAvatarEvent")
|
||||
return EventDelegate.Media.Image
|
||||
|
||||
let mainType = singleMediaInfo.media_mime.split("/")[0].toLowerCase()
|
||||
const mainType = singleMediaInfo.media_mime.split("/")[0].toLowerCase()
|
||||
|
||||
if (mainType === "image") return EventDelegate.Media.Image
|
||||
if (mainType === "video") return EventDelegate.Media.Video
|
||||
if (mainType === "audio") return EventDelegate.Media.Audio
|
||||
|
||||
let fileEvents = ["RoomMessageFile", "RoomEncryptedFile"]
|
||||
const fileEvents = ["RoomMessageFile", "RoomEncryptedFile"]
|
||||
|
||||
if (fileEvents.includes(singleMediaInfo.event_type))
|
||||
return EventDelegate.Media.File
|
||||
|
||||
// If this is a preview for a link in a normal message
|
||||
let ext = utils.urlExtension(mediaUrl)
|
||||
const ext = utils.urlExtension(mediaUrl)
|
||||
|
||||
if (imageExtensions.includes(ext)) return EventDelegate.Media.Image
|
||||
if (videoExtensions.includes(ext)) return EventDelegate.Media.Video
|
||||
|
|
|
@ -87,7 +87,7 @@ BoxPopup {
|
|||
// TODO: handle these: real user not found
|
||||
const lines = []
|
||||
|
||||
for (let [user, error] of failedInvites) {
|
||||
for (const [user, error] of failedInvites) {
|
||||
const type = py.getattr(
|
||||
py.getattr(error, "__class__"), "__name__",
|
||||
)
|
||||
|
|
|
@ -35,7 +35,7 @@ BoxPopup {
|
|||
|
||||
box.buttonCallbacks: ({
|
||||
ok: button => {
|
||||
let password = passwordField.text
|
||||
const password = passwordField.text
|
||||
okClicked = true
|
||||
button.loading = true
|
||||
errorMessage.text = ""
|
||||
|
|
|
@ -18,8 +18,8 @@ QtObject {
|
|||
|
||||
|
||||
function onCoroutineDone(uuid, result, error, traceback) {
|
||||
let onSuccess = Globals.pendingCoroutines[uuid].onSuccess
|
||||
let onError = Globals.pendingCoroutines[uuid].onError
|
||||
const onSuccess = Globals.pendingCoroutines[uuid].onSuccess
|
||||
const onError = Globals.pendingCoroutines[uuid].onError
|
||||
|
||||
delete Globals.pendingCoroutines[uuid]
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ QtObject {
|
|||
console.error("Failed creating component: ", comp.errorString())
|
||||
|
||||
} else if (! ready && status === Component.Ready) {
|
||||
let incu = comp.incubateObject(
|
||||
const incu = comp.incubateObject(
|
||||
parent, properties, Qt.Asynchronous,
|
||||
)
|
||||
|
||||
|
@ -165,7 +165,7 @@ QtObject {
|
|||
text = text.toLowerCase()
|
||||
}
|
||||
|
||||
for (let word of filter.split(" ")) {
|
||||
for (const word of filter.split(" ")) {
|
||||
if (word && ! text.includes(word)) {
|
||||
return false
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ QtObject {
|
|||
|
||||
|
||||
function filterMatchesAny(filter, ...texts) {
|
||||
for (let text of texts) {
|
||||
for (const text of texts) {
|
||||
if (filterMatches(filter, text)) return true
|
||||
}
|
||||
return false
|
||||
|
@ -184,11 +184,11 @@ QtObject {
|
|||
|
||||
function fitSize(minWidth, minHeight, width, height, maxWidth, maxHeight) {
|
||||
if (width >= height) {
|
||||
let new_width = Math.min(Math.max(width, minWidth), maxWidth)
|
||||
const new_width = Math.min(Math.max(width, minWidth), maxWidth)
|
||||
return Qt.size(new_width, height / (width / new_width))
|
||||
}
|
||||
|
||||
let new_height = Math.min(Math.max(height, minHeight), maxHeight)
|
||||
const new_height = Math.min(Math.max(height, minHeight), maxHeight)
|
||||
return Qt.size(width / (height / new_height), new_height)
|
||||
}
|
||||
|
||||
|
@ -231,9 +231,9 @@ QtObject {
|
|||
|
||||
|
||||
function formatDuration(milliseconds) {
|
||||
let totalSeconds = milliseconds / 1000
|
||||
const totalSeconds = milliseconds / 1000
|
||||
|
||||
let hours = Math.floor(totalSeconds / 3600)
|
||||
const hours = Math.floor(totalSeconds / 3600)
|
||||
let minutes = Math.floor((totalSeconds % 3600) / 60)
|
||||
let seconds = Math.floor(totalSeconds % 60)
|
||||
|
||||
|
|
|
@ -50,9 +50,9 @@ ApplicationWindow {
|
|||
if (! obj.saveName || ! obj.saveProperties ||
|
||||
obj.saveProperties.length < 1) return
|
||||
|
||||
let propertyValues = {}
|
||||
const propertyValues = {}
|
||||
|
||||
for (let prop of obj.saveProperties) {
|
||||
for (const prop of obj.saveProperties) {
|
||||
propertyValues[prop] = obj[prop]
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user