'use client' import type { FC } from 'react' import React, { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import { useContext } from 'use-context-selector' import cn from 'classnames' import { useSelectedLayoutSegments } from 'next/navigation' import Link from 'next/link' import Toast from '../../base/toast' import Item from './app-nav-item' import { fetchInstalledAppList as doFetchInstalledAppList, uninstallApp, updatePinStatus } from '@/service/explore' import ExploreContext from '@/context/explore-context' import Confirm from '@/app/components/base/confirm' const SelectedDiscoveryIcon = () => ( ) const DiscoveryIcon = () => ( ) const SideBar: FC<{ controlUpdateInstalledApps: number }> = ({ controlUpdateInstalledApps, }) => { const { t } = useTranslation() const segments = useSelectedLayoutSegments() const lastSegment = segments.slice(-1)[0] const isDiscoverySelected = lastSegment === 'apps' const { installedApps, setInstalledApps } = useContext(ExploreContext) const fetchInstalledAppList = async () => { const { installed_apps }: any = await doFetchInstalledAppList() setInstalledApps(installed_apps) } const [showConfirm, setShowConfirm] = useState(false) const [currId, setCurrId] = useState('') const handleDelete = async () => { const id = currId await uninstallApp(id) setShowConfirm(false) Toast.notify({ type: 'success', message: t('common.api.remove'), }) fetchInstalledAppList() } const handleUpdatePinStatus = async (id: string, isPinned: boolean) => { await updatePinStatus(id, isPinned) Toast.notify({ type: 'success', message: t('common.api.success'), }) fetchInstalledAppList() } useEffect(() => { fetchInstalledAppList() }, []) useEffect(() => { fetchInstalledAppList() }, [controlUpdateInstalledApps]) return (