@jbrowse/core
Version:
JBrowse 2 core libraries used by plugins
43 lines (42 loc) • 2.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const material_1 = require("@mui/material");
const mui_1 = require("tss-react/mui");
const util_1 = require("../../util");
const tracks_1 = require("../../util/tracks");
function isLocalPathLocation(loc) {
return 'localPath' in loc;
}
function isBlobLocation(loc) {
return 'blobId' in loc;
}
const useStyles = (0, mui_1.makeStyles)()(theme => ({
filename: {
marginLeft: theme.spacing(1),
},
}));
function LocalFileChooser({ location, setLocation, }) {
const { classes } = useStyles();
const filename = location &&
((isBlobLocation(location) && location.name) ||
(isLocalPathLocation(location) && location.localPath));
const needToReload = location && isBlobLocation(location) && !(0, tracks_1.getBlob)(location.blobId);
return ((0, jsx_runtime_1.jsxs)(material_1.Box, { display: "flex", flexDirection: "row", alignItems: "center", children: [(0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(material_1.FormControl, { fullWidth: true, children: (0, jsx_runtime_1.jsxs)(material_1.Button, { variant: "outlined", component: "label", children: ["Choose File", (0, jsx_runtime_1.jsx)("input", { type: "file", hidden: true, onChange: ({ target }) => {
var _a;
const file = (_a = target.files) === null || _a === void 0 ? void 0 : _a[0];
if (file) {
if (util_1.isElectron) {
const { webUtils } = window.require('electron');
setLocation({
localPath: webUtils.getPathForFile(file),
locationType: 'LocalPathLocation',
});
}
else {
setLocation((0, tracks_1.storeBlobLocation)({ blob: file }));
}
}
} })] }) }) }), (0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { component: "span", className: classes.filename, color: filename ? 'initial' : 'textSecondary', children: filename || 'No file chosen' }), needToReload ? ((0, jsx_runtime_1.jsx)(material_1.Typography, { color: "error", children: "(need to reload)" })) : null] })] }));
}
exports.default = LocalFileChooser;