()
| 16 | * @returns {{Promise<string>} Favorites section HTML code |
| 17 | */ |
| 18 | const Favorites = async (): Promise<string> => { |
| 19 | if (!FavoritesData) { |
| 20 | FavoritesData = new FavoritesAPI(); |
| 21 | await FavoritesData.build(); |
| 22 | } |
| 23 | const data = await Storage.get('favorites'); // Get user favorites data on sidebar |
| 24 | const favorites = data?.favorites ?? (await defaultFavorites()); |
| 25 | |
| 26 | let result = '<section class="home-section">'; |
| 27 | result += `<h1 class="section-title">${await Translate('Favorites')}</h1>`; |
| 28 | const defaultFavoritesList = (await defaultFavorites()).map((favorite) => favorite.name); |
| 29 | for (const favorite of favorites) { |
| 30 | if (!favorite.path) continue; |
| 31 | if (favorite.path === 'xplorer://Home') continue; |
| 32 | const fileData = new FileAPI(favorite.path); |
| 33 | const exists = await fileData.exists(); |
| 34 | if (!exists && !(await isDefaultFavorite(favorite.path))) continue; |
| 35 | let icon = favorite.icon; |
| 36 | if (!icon) { |
| 37 | if (defaultFavoritesList.indexOf(favorite.name) === -1) { |
| 38 | const isdir = await new DirectoryAPI(favorite.path).isDir(); |
| 39 | icon = await fileThumbnail(exists ? favorite.path : favorite.name, isdir ? 'folder' : 'file', false); |
| 40 | } else { |
| 41 | icon = await fileThumbnail(favorite.name.toLowerCase(), 'folder', false); |
| 42 | } |
| 43 | } |
| 44 | result += `<div |
| 45 | class="favorite file card-hover-effect" |
| 46 | data-isdir="${(await isDefaultFavorite(favorite.path)) ? true : await fileData.isDir()}" |
| 47 | data-path="${favorite.path}" |
| 48 | > |
| 49 | <h3 class="favorite-title"> |
| 50 | <img |
| 51 | src="${icon}" |
| 52 | alt="${favorite.name} icon" |
| 53 | class="favorite-icon" |
| 54 | />${favorite.name} |
| 55 | </h3> |
| 56 | </div>`; |
| 57 | } |
| 58 | return result; |
| 59 | }; |
| 60 | export default Favorites; |
nothing calls this directly
no test coverage detected