UNPKG

cozy-search

Version:

UI components about search bar and IA assistant

109 lines (89 loc) 3.27 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.getIconForSearchResult = exports.getDriveMimeTypeIcon = void 0; var _twakeIcons = require("@linagora/twake-icons"); var _get = _interopRequireDefault(require("lodash/get")); var _file = require("cozy-client/dist/models/file"); var _DocsIcon = _interopRequireDefault(require("./Icons/DocsIcon")); var _EncryptedFolderIcon = _interopRequireDefault(require("./Icons/EncryptedFolderIcon")); var _getFileMimetype = require("./getFileMimetype"); var getIconForSearchResult = function getIconForSearchResult(searchResult) { if (searchResult.doc._type === 'io.cozy.apps') { return { type: 'app', app: searchResult.doc }; } if (searchResult.slug === 'notes') { return { type: 'component', component: _twakeIcons.FileTypeNote }; } if (searchResult.slug === 'drive') { return { type: 'component', component: getDriveMimeTypeIcon(searchResult.doc) }; } if (searchResult.slug === 'contacts') { return { type: 'component', component: _twakeIcons.Contacts }; } return { type: 'component', component: _twakeIcons.FileTypeFiles }; }; /** * Returns the appropriate icon for a given file based on its mime type and other properties. * * This method has been copied from cozy-drive * * See source: https://github.com/cozy/cozy-drive/blob/fbe2df67199683b23a40f476ccdacb00ee027459/src/lib/getMimeTypeIcon.js * * @param {import('cozy-client/types/types').IOCozyFile} file - The io.cozy.files . * @param {Object} [options] - Additional options. * @param {boolean} [options.isEncrypted] - Indicates whether the file is encrypted. Default is false. * @returns {import('react').ReactNode} - The icon corresponding to the file's mime type. */ exports.getIconForSearchResult = getIconForSearchResult; var getDriveMimeTypeIcon = function getDriveMimeTypeIcon(file) { var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, _ref$isEncrypted = _ref.isEncrypted, isEncrypted = _ref$isEncrypted === void 0 ? false : _ref$isEncrypted; var isDirectory = file.type === 'directory'; var name = file.name, mime = file.mime; if (isEncrypted) { return _EncryptedFolderIcon.default; } if (isDirectory) { return _twakeIcons.FileTypeFolder; } else if ((0, _file.isNote)(file)) { return _twakeIcons.FileTypeNote; } else if ((0, _file.isDocs)(file)) { return _DocsIcon.default; } else { var iconsByMimeType = { audio: _twakeIcons.FileTypeAudio, bin: _twakeIcons.FileTypeBin, code: _twakeIcons.FileTypeCode, image: _twakeIcons.FileTypeImage, pdf: _twakeIcons.FileTypePdf, slide: _twakeIcons.FileTypeSlide, sheet: _twakeIcons.FileTypeSheet, text: _twakeIcons.FileTypeText, video: _twakeIcons.FileTypeVideo, zip: _twakeIcons.FileTypeZip }; var type = (0, _getFileMimetype.getFileMimetype)(iconsByMimeType)(mime, name); return (0, _get.default)(iconsByMimeType, type, _twakeIcons.FileTypeFiles); } }; exports.getDriveMimeTypeIcon = getDriveMimeTypeIcon;