You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

app.tsx 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import type { ActionItem, AppSearchResult } from './types'
  2. import type { App } from '@/types/app'
  3. import { fetchAppList } from '@/service/apps'
  4. import AppIcon from '../../base/app-icon'
  5. import { AppTypeIcon } from '../../app/type-selector'
  6. import { getRedirectionPath } from '@/utils/app-redirection'
  7. const parser = (apps: App[]): AppSearchResult[] => {
  8. return apps.map(app => ({
  9. id: app.id,
  10. title: app.name,
  11. description: app.description,
  12. type: 'app' as const,
  13. path: getRedirectionPath(true, {
  14. id: app.id,
  15. mode: app.mode,
  16. }),
  17. icon: (
  18. <div className='relative shrink-0'>
  19. <AppIcon
  20. size='large'
  21. iconType={app.icon_type}
  22. icon={app.icon}
  23. background={app.icon_background}
  24. imageUrl={app.icon_url}
  25. />
  26. <AppTypeIcon wrapperClassName='absolute -bottom-0.5 -right-0.5 w-4 h-4 rounded-[4px] border border-divider-regular outline outline-components-panel-on-panel-item-bg'
  27. className='h-3 w-3' type={app.mode} />
  28. </div>
  29. ),
  30. data: app,
  31. }))
  32. }
  33. export const appAction: ActionItem = {
  34. key: '@app',
  35. shortcut: '@app',
  36. title: 'Search Applications',
  37. description: 'Search and navigate to your applications',
  38. // action,
  39. search: async (_, searchTerm = '', _locale) => {
  40. try {
  41. const response = await fetchAppList({
  42. url: 'apps',
  43. params: {
  44. page: 1,
  45. name: searchTerm,
  46. },
  47. })
  48. const apps = response?.data || []
  49. return parser(apps)
  50. }
  51. catch (error) {
  52. console.warn('App search failed:', error)
  53. return []
  54. }
  55. },
  56. }