Fix lint issues in Drive components (#8613)

* fix(client): Fix lint issues in Drive components

* fix(client): only use !=/== for null comparisons

* Update drive.vue

Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
This commit is contained in:
Andreas Nedbal 2022-05-05 13:45:50 +02:00 committed by GitHub
parent dd8cb7846f
commit 7362c2da76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 84 additions and 84 deletions

View File

@ -42,7 +42,7 @@ const is = computed(() => {
"application/x-tar", "application/x-tar",
"application/gzip", "application/gzip",
"application/x-7z-compressed" "application/x-7z-compressed"
].some(e => e === props.file.type)) return 'archive'; ].some(archiveType => archiveType === props.file.type)) return 'archive';
return 'unknown'; return 'unknown';
}); });

View File

@ -33,8 +33,8 @@ withDefaults(defineProps<{
}); });
const emit = defineEmits<{ const emit = defineEmits<{
(e: 'done', r?: Misskey.entities.DriveFile[]): void; (ev: 'done', r?: Misskey.entities.DriveFile[]): void;
(e: 'closed'): void; (ev: 'closed'): void;
}>(); }>();
const dialog = ref<InstanceType<typeof XModalWindow>>(); const dialog = ref<InstanceType<typeof XModalWindow>>();

View File

@ -24,6 +24,6 @@ defineProps<{
}>(); }>();
const emit = defineEmits<{ const emit = defineEmits<{
(e: 'closed'): void; (ev: 'closed'): void;
}>(); }>();
</script> </script>

View File

@ -50,9 +50,9 @@ const props = withDefaults(defineProps<{
}); });
const emit = defineEmits<{ const emit = defineEmits<{
(e: 'chosen', r: Misskey.entities.DriveFile): void; (ev: 'chosen', r: Misskey.entities.DriveFile): void;
(e: 'dragstart'): void; (ev: 'dragstart'): void;
(e: 'dragend'): void; (ev: 'dragend'): void;
}>(); }>();
const isDragging = ref(false); const isDragging = ref(false);
@ -99,14 +99,14 @@ function onClick(ev: MouseEvent) {
} }
} }
function onContextmenu(e: MouseEvent) { function onContextmenu(ev: MouseEvent) {
os.contextMenu(getMenu(), e); os.contextMenu(getMenu(), ev);
} }
function onDragstart(e: DragEvent) { function onDragstart(ev: DragEvent) {
if (e.dataTransfer) { if (ev.dataTransfer) {
e.dataTransfer.effectAllowed = 'move'; ev.dataTransfer.effectAllowed = 'move';
e.dataTransfer.setData(_DATA_TRANSFER_DRIVE_FILE_, JSON.stringify(props.file)); ev.dataTransfer.setData(_DATA_TRANSFER_DRIVE_FILE_, JSON.stringify(props.file));
} }
isDragging.value = true; isDragging.value = true;
@ -137,7 +137,7 @@ function describe() {
title: i18n.ts.describeFile, title: i18n.ts.describeFile,
input: { input: {
placeholder: i18n.ts.inputNewDescription, placeholder: i18n.ts.inputNewDescription,
default: props.file.comment !== null ? props.file.comment : '', default: props.file.comment != null ? props.file.comment : '',
}, },
image: props.file image: props.file
}, { }, {
@ -146,7 +146,7 @@ function describe() {
let comment = result.result; let comment = result.result;
os.api('drive/files/update', { os.api('drive/files/update', {
fileId: props.file.id, fileId: props.file.id,
comment: comment.length == 0 ? null : comment comment: comment.length === 0 ? null : comment
}); });
} }
}, 'closed'); }, 'closed');

View File

@ -84,12 +84,12 @@ function onDragover(ev: DragEvent) {
return; return;
} }
const isFile = ev.dataTransfer.items[0].kind == 'file'; const isFile = ev.dataTransfer.items[0].kind === 'file';
const isDriveFile = ev.dataTransfer.types[0] == _DATA_TRANSFER_DRIVE_FILE_; const isDriveFile = ev.dataTransfer.types[0] === _DATA_TRANSFER_DRIVE_FILE_;
const isDriveFolder = ev.dataTransfer.types[0] == _DATA_TRANSFER_DRIVE_FOLDER_; const isDriveFolder = ev.dataTransfer.types[0] === _DATA_TRANSFER_DRIVE_FOLDER_;
if (isFile || isDriveFile || isDriveFolder) { if (isFile || isDriveFile || isDriveFolder) {
ev.dataTransfer.dropEffect = ev.dataTransfer.effectAllowed == 'all' ? 'copy' : 'move'; ev.dataTransfer.dropEffect = ev.dataTransfer.effectAllowed === 'all' ? 'copy' : 'move';
} else { } else {
ev.dataTransfer.dropEffect = 'none'; ev.dataTransfer.dropEffect = 'none';
} }
@ -118,7 +118,7 @@ function onDrop(ev: DragEvent) {
//#region //#region
const driveFile = ev.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FILE_); const driveFile = ev.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FILE_);
if (driveFile != null && driveFile != '') { if (driveFile != null && driveFile !== '') {
const file = JSON.parse(driveFile); const file = JSON.parse(driveFile);
emit('removeFile', file.id); emit('removeFile', file.id);
os.api('drive/files/update', { os.api('drive/files/update', {
@ -130,11 +130,11 @@ function onDrop(ev: DragEvent) {
//#region //#region
const driveFolder = ev.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FOLDER_); const driveFolder = ev.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FOLDER_);
if (driveFolder != null && driveFolder != '') { if (driveFolder != null && driveFolder !== '') {
const folder = JSON.parse(driveFolder); const folder = JSON.parse(driveFolder);
// reject // reject
if (folder.id == props.folder.id) return; if (folder.id === props.folder.id) return;
emit('removeFolder', folder.id); emit('removeFolder', folder.id);
os.api('drive/folders/update', { os.api('drive/folders/update', {

View File

@ -24,10 +24,10 @@ const props = defineProps<{
}>(); }>();
const emit = defineEmits<{ const emit = defineEmits<{
(e: 'move', v?: Misskey.entities.DriveFolder): void; (ev: 'move', v?: Misskey.entities.DriveFolder): void;
(e: 'upload', file: File, folder?: Misskey.entities.DriveFolder | null): void; (ev: 'upload', file: File, folder?: Misskey.entities.DriveFolder | null): void;
(e: 'removeFile', v: Misskey.entities.DriveFile['id']): void; (ev: 'removeFile', v: Misskey.entities.DriveFile['id']): void;
(e: 'removeFolder', v: Misskey.entities.DriveFolder['id']): void; (ev: 'removeFolder', v: Misskey.entities.DriveFolder['id']): void;
}>(); }>();
const hover = ref(false); const hover = ref(false);
@ -45,22 +45,22 @@ function onMouseout() {
hover.value = false; hover.value = false;
} }
function onDragover(e: DragEvent) { function onDragover(ev: DragEvent) {
if (!e.dataTransfer) return; if (!ev.dataTransfer) return;
// //
if (props.folder == null && props.parentFolder == null) { if (props.folder == null && props.parentFolder == null) {
e.dataTransfer.dropEffect = 'none'; ev.dataTransfer.dropEffect = 'none';
} }
const isFile = e.dataTransfer.items[0].kind == 'file'; const isFile = ev.dataTransfer.items[0].kind === 'file';
const isDriveFile = e.dataTransfer.types[0] == _DATA_TRANSFER_DRIVE_FILE_; const isDriveFile = ev.dataTransfer.types[0] === _DATA_TRANSFER_DRIVE_FILE_;
const isDriveFolder = e.dataTransfer.types[0] == _DATA_TRANSFER_DRIVE_FOLDER_; const isDriveFolder = ev.dataTransfer.types[0] === _DATA_TRANSFER_DRIVE_FOLDER_;
if (isFile || isDriveFile || isDriveFolder) { if (isFile || isDriveFile || isDriveFolder) {
e.dataTransfer.dropEffect = e.dataTransfer.effectAllowed == 'all' ? 'copy' : 'move'; ev.dataTransfer.dropEffect = ev.dataTransfer.effectAllowed === 'all' ? 'copy' : 'move';
} else { } else {
e.dataTransfer.dropEffect = 'none'; ev.dataTransfer.dropEffect = 'none';
} }
return false; return false;
@ -74,22 +74,22 @@ function onDragleave() {
if (props.folder || props.parentFolder) draghover.value = false; if (props.folder || props.parentFolder) draghover.value = false;
} }
function onDrop(e: DragEvent) { function onDrop(ev: DragEvent) {
draghover.value = false; draghover.value = false;
if (!e.dataTransfer) return; if (!ev.dataTransfer) return;
// //
if (e.dataTransfer.files.length > 0) { if (ev.dataTransfer.files.length > 0) {
for (const file of Array.from(e.dataTransfer.files)) { for (const file of Array.from(ev.dataTransfer.files)) {
emit('upload', file, props.folder); emit('upload', file, props.folder);
} }
return; return;
} }
//#region //#region
const driveFile = e.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FILE_); const driveFile = ev.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FILE_);
if (driveFile != null && driveFile != '') { if (driveFile != null && driveFile !== '') {
const file = JSON.parse(driveFile); const file = JSON.parse(driveFile);
emit('removeFile', file.id); emit('removeFile', file.id);
os.api('drive/files/update', { os.api('drive/files/update', {
@ -100,11 +100,11 @@ function onDrop(e: DragEvent) {
//#endregion //#endregion
//#region //#region
const driveFolder = e.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FOLDER_); const driveFolder = ev.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FOLDER_);
if (driveFolder != null && driveFolder != '') { if (driveFolder != null && driveFolder !== '') {
const folder = JSON.parse(driveFolder); const folder = JSON.parse(driveFolder);
// reject // reject
if (props.folder && folder.id == props.folder.id) return; if (props.folder && folder.id === props.folder.id) return;
emit('removeFolder', folder.id); emit('removeFolder', folder.id);
os.api('drive/folders/update', { os.api('drive/folders/update', {
folderId: folder.id, folderId: folder.id,

View File

@ -110,11 +110,11 @@ const props = withDefaults(defineProps<{
}); });
const emit = defineEmits<{ const emit = defineEmits<{
(e: 'selected', v: Misskey.entities.DriveFile | Misskey.entities.DriveFolder): void; (ev: 'selected', v: Misskey.entities.DriveFile | Misskey.entities.DriveFolder): void;
(e: 'change-selection', v: Misskey.entities.DriveFile[] | Misskey.entities.DriveFolder[]): void; (ev: 'change-selection', v: Misskey.entities.DriveFile[] | Misskey.entities.DriveFolder[]): void;
(e: 'move-root'): void; (ev: 'move-root'): void;
(e: 'cd', v: Misskey.entities.DriveFolder | null): void; (ev: 'cd', v: Misskey.entities.DriveFolder | null): void;
(e: 'open-folder', v: Misskey.entities.DriveFolder): void; (ev: 'open-folder', v: Misskey.entities.DriveFolder): void;
}>(); }>();
const loadMoreFiles = ref<InstanceType<typeof MkButton>>(); const loadMoreFiles = ref<InstanceType<typeof MkButton>>();
@ -153,7 +153,7 @@ function onStreamDriveFileCreated(file: Misskey.entities.DriveFile) {
function onStreamDriveFileUpdated(file: Misskey.entities.DriveFile) { function onStreamDriveFileUpdated(file: Misskey.entities.DriveFile) {
const current = folder.value ? folder.value.id : null; const current = folder.value ? folder.value.id : null;
if (current != file.folderId) { if (current !== file.folderId) {
removeFile(file); removeFile(file);
} else { } else {
addFile(file, true); addFile(file, true);
@ -170,7 +170,7 @@ function onStreamDriveFolderCreated(createdFolder: Misskey.entities.DriveFolder)
function onStreamDriveFolderUpdated(updatedFolder: Misskey.entities.DriveFolder) { function onStreamDriveFolderUpdated(updatedFolder: Misskey.entities.DriveFolder) {
const current = folder.value ? folder.value.id : null; const current = folder.value ? folder.value.id : null;
if (current != updatedFolder.parentId) { if (current !== updatedFolder.parentId) {
removeFolder(updatedFolder); removeFolder(updatedFolder);
} else { } else {
addFolder(updatedFolder, true); addFolder(updatedFolder, true);
@ -181,23 +181,23 @@ function onStreamDriveFolderDeleted(folderId: string) {
removeFolder(folderId); removeFolder(folderId);
} }
function onDragover(e: DragEvent): any { function onDragover(ev: DragEvent): any {
if (!e.dataTransfer) return; if (!ev.dataTransfer) return;
// //
if (isDragSource.value) { if (isDragSource.value) {
// //
e.dataTransfer.dropEffect = 'none'; ev.dataTransfer.dropEffect = 'none';
return; return;
} }
const isFile = e.dataTransfer.items[0].kind == 'file'; const isFile = ev.dataTransfer.items[0].kind === 'file';
const isDriveFile = e.dataTransfer.types[0] == _DATA_TRANSFER_DRIVE_FILE_; const isDriveFile = ev.dataTransfer.types[0] === _DATA_TRANSFER_DRIVE_FILE_;
const isDriveFolder = e.dataTransfer.types[0] == _DATA_TRANSFER_DRIVE_FOLDER_; const isDriveFolder = ev.dataTransfer.types[0] === _DATA_TRANSFER_DRIVE_FOLDER_;
if (isFile || isDriveFile || isDriveFolder) { if (isFile || isDriveFile || isDriveFolder) {
e.dataTransfer.dropEffect = e.dataTransfer.effectAllowed == 'all' ? 'copy' : 'move'; ev.dataTransfer.dropEffect = ev.dataTransfer.effectAllowed === 'all' ? 'copy' : 'move';
} else { } else {
e.dataTransfer.dropEffect = 'none'; ev.dataTransfer.dropEffect = 'none';
} }
return false; return false;
@ -211,24 +211,24 @@ function onDragleave() {
draghover.value = false; draghover.value = false;
} }
function onDrop(e: DragEvent): any { function onDrop(ev: DragEvent): any {
draghover.value = false; draghover.value = false;
if (!e.dataTransfer) return; if (!ev.dataTransfer) return;
// //
if (e.dataTransfer.files.length > 0) { if (ev.dataTransfer.files.length > 0) {
for (const file of Array.from(e.dataTransfer.files)) { for (const file of Array.from(ev.dataTransfer.files)) {
upload(file, folder.value); upload(file, folder.value);
} }
return; return;
} }
//#region //#region
const driveFile = e.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FILE_); const driveFile = ev.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FILE_);
if (driveFile != null && driveFile != '') { if (driveFile != null && driveFile !== '') {
const file = JSON.parse(driveFile); const file = JSON.parse(driveFile);
if (files.value.some(f => f.id == file.id)) return; if (files.value.some(f => f.id === file.id)) return;
removeFile(file.id); removeFile(file.id);
os.api('drive/files/update', { os.api('drive/files/update', {
fileId: file.id, fileId: file.id,
@ -238,13 +238,13 @@ function onDrop(e: DragEvent): any {
//#endregion //#endregion
//#region //#region
const driveFolder = e.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FOLDER_); const driveFolder = ev.dataTransfer.getData(_DATA_TRANSFER_DRIVE_FOLDER_);
if (driveFolder != null && driveFolder != '') { if (driveFolder != null && driveFolder !== '') {
const droppedFolder = JSON.parse(driveFolder); const droppedFolder = JSON.parse(driveFolder);
// reject // reject
if (folder.value && droppedFolder.id == folder.value.id) return false; if (folder.value && droppedFolder.id === folder.value.id) return false;
if (folders.value.some(f => f.id == droppedFolder.id)) return false; if (folders.value.some(f => f.id === droppedFolder.id)) return false;
removeFolder(droppedFolder.id); removeFolder(droppedFolder.id);
os.api('drive/folders/update', { os.api('drive/folders/update', {
folderId: droppedFolder.id, folderId: droppedFolder.id,
@ -357,16 +357,16 @@ function onChangeFileInput() {
} }
function upload(file: File, folderToUpload?: Misskey.entities.DriveFolder | null) { function upload(file: File, folderToUpload?: Misskey.entities.DriveFolder | null) {
uploadFile(file, (folderToUpload && typeof folderToUpload == 'object') ? folderToUpload.id : null, undefined, keepOriginal.value).then(res => { uploadFile(file, (folderToUpload && typeof folderToUpload === 'object') ? folderToUpload.id : null, undefined, keepOriginal.value).then(res => {
addFile(res, true); addFile(res, true);
}); });
} }
function chooseFile(file: Misskey.entities.DriveFile) { function chooseFile(file: Misskey.entities.DriveFile) {
const isAlreadySelected = selectedFiles.value.some(f => f.id == file.id); const isAlreadySelected = selectedFiles.value.some(f => f.id === file.id);
if (props.multiple) { if (props.multiple) {
if (isAlreadySelected) { if (isAlreadySelected) {
selectedFiles.value = selectedFiles.value.filter(f => f.id != file.id); selectedFiles.value = selectedFiles.value.filter(f => f.id !== file.id);
} else { } else {
selectedFiles.value.push(file); selectedFiles.value.push(file);
} }
@ -382,10 +382,10 @@ function chooseFile(file: Misskey.entities.DriveFile) {
} }
function chooseFolder(folderToChoose: Misskey.entities.DriveFolder) { function chooseFolder(folderToChoose: Misskey.entities.DriveFolder) {
const isAlreadySelected = selectedFolders.value.some(f => f.id == folderToChoose.id); const isAlreadySelected = selectedFolders.value.some(f => f.id === folderToChoose.id);
if (props.multiple) { if (props.multiple) {
if (isAlreadySelected) { if (isAlreadySelected) {
selectedFolders.value = selectedFolders.value.filter(f => f.id != folderToChoose.id); selectedFolders.value = selectedFolders.value.filter(f => f.id !== folderToChoose.id);
} else { } else {
selectedFolders.value.push(folderToChoose); selectedFolders.value.push(folderToChoose);
} }
@ -404,7 +404,7 @@ function move(target?: Misskey.entities.DriveFolder) {
if (!target) { if (!target) {
goRoot(); goRoot();
return; return;
} else if (typeof target == 'object') { } else if (typeof target === 'object') {
target = target.id; target = target.id;
} }
@ -430,9 +430,9 @@ function move(target?: Misskey.entities.DriveFolder) {
function addFolder(folderToAdd: Misskey.entities.DriveFolder, unshift = false) { function addFolder(folderToAdd: Misskey.entities.DriveFolder, unshift = false) {
const current = folder.value ? folder.value.id : null; const current = folder.value ? folder.value.id : null;
if (current != folderToAdd.parentId) return; if (current !== folderToAdd.parentId) return;
if (folders.value.some(f => f.id == folderToAdd.id)) { if (folders.value.some(f => f.id === folderToAdd.id)) {
const exist = folders.value.map(f => f.id).indexOf(folderToAdd.id); const exist = folders.value.map(f => f.id).indexOf(folderToAdd.id);
folders.value[exist] = folderToAdd; folders.value[exist] = folderToAdd;
return; return;
@ -447,9 +447,9 @@ function addFolder(folderToAdd: Misskey.entities.DriveFolder, unshift = false) {
function addFile(fileToAdd: Misskey.entities.DriveFile, unshift = false) { function addFile(fileToAdd: Misskey.entities.DriveFile, unshift = false) {
const current = folder.value ? folder.value.id : null; const current = folder.value ? folder.value.id : null;
if (current != fileToAdd.folderId) return; if (current !== fileToAdd.folderId) return;
if (files.value.some(f => f.id == fileToAdd.id)) { if (files.value.some(f => f.id === fileToAdd.id)) {
const exist = files.value.map(f => f.id).indexOf(fileToAdd.id); const exist = files.value.map(f => f.id).indexOf(fileToAdd.id);
files.value[exist] = fileToAdd; files.value[exist] = fileToAdd;
return; return;
@ -464,12 +464,12 @@ function addFile(fileToAdd: Misskey.entities.DriveFile, unshift = false) {
function removeFolder(folderToRemove: Misskey.entities.DriveFolder | string) { function removeFolder(folderToRemove: Misskey.entities.DriveFolder | string) {
const folderIdToRemove = typeof folderToRemove === 'object' ? folderToRemove.id : folderToRemove; const folderIdToRemove = typeof folderToRemove === 'object' ? folderToRemove.id : folderToRemove;
folders.value = folders.value.filter(f => f.id != folderIdToRemove); folders.value = folders.value.filter(f => f.id !== folderIdToRemove);
} }
function removeFile(file: Misskey.entities.DriveFile | string) { function removeFile(file: Misskey.entities.DriveFile | string) {
const fileId = typeof file === 'object' ? file.id : file; const fileId = typeof file === 'object' ? file.id : file;
files.value = files.value.filter(f => f.id != fileId); files.value = files.value.filter(f => f.id !== fileId);
} }
function appendFile(file: Misskey.entities.DriveFile) { function appendFile(file: Misskey.entities.DriveFile) {
@ -512,7 +512,7 @@ async function fetch() {
folderId: folder.value ? folder.value.id : null, folderId: folder.value ? folder.value.id : null,
limit: foldersMax + 1 limit: foldersMax + 1
}).then(fetchedFolders => { }).then(fetchedFolders => {
if (fetchedFolders.length == foldersMax + 1) { if (fetchedFolders.length === foldersMax + 1) {
moreFolders.value = true; moreFolders.value = true;
fetchedFolders.pop(); fetchedFolders.pop();
} }
@ -524,7 +524,7 @@ async function fetch() {
type: props.type, type: props.type,
limit: filesMax + 1 limit: filesMax + 1
}).then(fetchedFiles => { }).then(fetchedFiles => {
if (fetchedFiles.length == filesMax + 1) { if (fetchedFiles.length === filesMax + 1) {
moreFiles.value = true; moreFiles.value = true;
fetchedFiles.pop(); fetchedFiles.pop();
} }
@ -551,7 +551,7 @@ function fetchMoreFiles() {
untilId: files.value[files.value.length - 1].id, untilId: files.value[files.value.length - 1].id,
limit: max + 1 limit: max + 1
}).then(files => { }).then(files => {
if (files.length == max + 1) { if (files.length === max + 1) {
moreFiles.value = true; moreFiles.value = true;
files.pop(); files.pop();
} else { } else {