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

Function getFavoritesElement

src/Components/Layout/sidebar.ts:44–77  ·  view source on GitHub ↗
(favorites: Favorites[])

Source from the content-addressed store, hash-verified

42 }
43 // Functions to get favorites element
44 const getFavoritesElement = async (favorites: Favorites[]) => {
45 let favoritesElement = '';
46 const defaultFavoritesList = (await defaultFavorites()).map((favorite) => favorite.name);
47 for (const favorite of favorites) {
48 if (!favorite.path) continue;
49 const exists = await new FileAPI(favorite.path).exists();
50 if (!(await isDefaultFavorite(favorite.path)) && !favorite.path.startsWith('xplorer://')) {
51 if (!exists) continue;
52 }
53 const isdir = favorite.path.startsWith('xplorer://') ? true : await new DirectoryAPI(favorite.path).isDir();
54 favoritesElement += `<span data-path = "${
55 favorite.path
56 }" data-isdir="${isdir}" class="sidebar-hover-effect sidebar-item"><img src="${await fileThumbnail(
57 exists && !(await isDefaultFavorite(favorite.path)) ? favorite.path : favorite.name,
58 defaultFavoritesList.indexOf(favorite.name) === -1 && favorite.path !== 'xplorer://Home' ? (isdir ? 'folder' : 'file') : 'sidebar',
59 false
60 )}" alt="${favorite.name} icon"><span class="sidebar-text">${await Translate(favorite.name)}</span></span>`;
61 }
62 const result = `<div class="sidebar-nav-item ${sidebar?.hideSection?.favorites ? 'nav-hide-item' : ''}">
63 <div class="sidebar-hover-effect">
64 <span class="sidebar-nav-item-dropdown-btn" data-section="favorites"><img src="${await fileThumbnail(
65 'Favorites',
66 'sidebar',
67 false
68 )}" alt="Favorites icon"><span class="sidebar-text">${await Translate(
69 'Favorites'
70 )}</span><div class="sidebar-nav-item-dropdown-spacer"></div></span>
71 </div>
72 <div class="sidebar-nav-item-dropdown-container">
73 ${favoritesElement}
74 </div>
75 </div>`;
76 return result;
77 };
78
79 const favorites = await Storage.get('favorites');
80 const _favorites = IsValid(favorites?.favorites)

Callers 1

createSidebarFunction · 0.85

Calls 6

defaultFavoritesFunction · 0.85
fileThumbnailFunction · 0.85
TranslateFunction · 0.85
isDefaultFavoriteFunction · 0.70
existsMethod · 0.45
isDirMethod · 0.45

Tested by

no test coverage detected