All files / app/codeCharta/ui/customConfigs/uploadCustomConfigButton uploadCustomConfigButton.component.ts

46.66% Statements 7/15
100% Branches 0/0
0% Functions 0/3
38.46% Lines 5/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 327x 7x 7x 7x               7x                                        
import { Component } from "@angular/core"
import { CustomConfigHelper } from "../../../util/customConfigHelper"
import { createCCFileInput } from "../../../util/uploadFiles/createCCFileInput"
import { readFiles } from "../../../util/uploadFiles/readFiles"
 
@Component({
    selector: "cc-upload-custom-config-button",
    templateUrl: "./uploadCustomConfigButton.component.html",
    styleUrls: ["../customConfigButtons.scss"],
    standalone: true
})
export class UploadCustomConfigButtonComponent {
    upload() {
        const fileInput = createCCFileInput()
        fileInput.addEventListener("change", () => {
            void this.uploadOnEvent(fileInput)
        })
        fileInput.click()
    }
 
    private async uploadOnEvent(fileInput: HTMLInputElement) {
        const customConfigsContent = await Promise.all(readFiles(fileInput.files))
        for (const customConfigContent of customConfigsContent) {
            try {
                CustomConfigHelper.importCustomConfigs(customConfigContent)
            } catch {
                // Explicitly ignored
            }
        }
    }
}