MCPcopy
hub / github.com/kimlimjustin/xplorer / Favorites

Function Favorites

src/Components/Favorites/favorites.ts:18–59  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16 * @returns {{Promise<string>} Favorites section HTML code
17 */
18const 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};
60export default Favorites;

Callers

nothing calls this directly

Calls 8

existsMethod · 0.95
isDirMethod · 0.95
defaultFavoritesFunction · 0.85
TranslateFunction · 0.85
fileThumbnailFunction · 0.85
getMethod · 0.80
isDefaultFavoriteFunction · 0.70
buildMethod · 0.45

Tested by

no test coverage detected