Skip to content

TagSpaces is an offline, open source, document manager with tagging support

feat: showing badges in the entry tabs for ai chats and description

Ilian Sapundshiev7403ab837246
diff --git a/src/renderer/AppConfig.ts b/src/renderer/AppConfig.ts
index 54f6de5c3..bc8f1a01b 100644
--- a/src/renderer/AppConfig.ts
+++ b/src/renderer/AppConfig.ts
@@ -172,6 +172,7 @@ AppConfig.defaultFileColor = '#33b5be';
AppConfig.defaultCSSRadius = '10px';
AppConfig.defaultSpaceBetweenButtons = '10px';
AppConfig.aiFolder = 'ai';
+AppConfig.aiChatFileName = 'tsc.json';
AppConfig.sidecarRevisionExtension = '.meta';
AppConfig.defaultMapBounds =
typeof window !== 'undefined' && window.ExtDefaultMapBounds !== undefined
diff --git a/src/renderer/components/EntryContainerTabs.tsx b/src/renderer/components/EntryContainerTabs.tsx
index 57216f46e..c0991bc43 100644
--- a/src/renderer/components/EntryContainerTabs.tsx
+++ b/src/renderer/components/EntryContainerTabs.tsx
@@ -30,7 +30,7 @@ import {
getEntryContainerTab,
getMapTileServer,
} from '-/reducers/settings';
-import { Box, Tab, Tabs, TabsProps } from '@mui/material';
+import { Badge, Box, Tab, Tabs, TabsProps } from '@mui/material';
import { styled, useTheme } from '@mui/material/styles';
import React, { useEffect, useReducer, useRef } from 'react';
import { useDispatch, useSelector } from 'react-redux';
@@ -191,19 +191,29 @@ function EntryContainerTabs(props: EntryContainerTabsProps) {
<Tab
key={'key' + tab.name + index}
data-tid={tab.name + 'TID'}
- // @ts-ignore
- icon={tab.icon}
+ icon={
+ <Badge
+ color="primary"
+ variant="dot"
+ invisible={!tab.showBadge}
+ anchorOrigin={{
+ vertical: 'top',
+ horizontal: 'right',
+ }}
+ >
+ {tab.icon}
+ </Badge>
+ }
label={tab.title}
sx={{
paddingLeft: 0,
paddingRight: 0,
- fontSize: '12px',
+ fontSize: '11px',
fontWeight: 'normal',
textTransform: 'none',
paddingTop: '0px',
paddingBottom: '0px',
- minHeight: '60px', // 68px
- // marginLeft: '-8px',
+ minHeight: '60px',
marginRight: '-8px',
borderRadius: AppConfig.defaultCSSRadius,
'&:hover': {
diff --git a/src/renderer/hooks/ChatProvider.tsx b/src/renderer/hooks/ChatProvider.tsx
index acfbdffcc..032c968d2 100644
--- a/src/renderer/hooks/ChatProvider.tsx
+++ b/src/renderer/hooks/ChatProvider.tsx
@@ -702,7 +702,7 @@ export const ChatContextProvider = ({ children }: ChatContextProviderProps) => {
? currentLocation.getDirSeparator()
: AppConfig.dirSeparator;
const metaFolder = getMetaDirectoryPath(openedEntry.path, dirSeparator);
- const fileName = name ? name : 'tsc.json';
+ const fileName = name ? name : AppConfig.aiChatFileName;
return (
metaFolder + dirSeparator + AppConfig.aiFolder + dirSeparator + fileName
);
diff --git a/src/renderer/hooks/EntryPropsTabsContextProvider.tsx b/src/renderer/hooks/EntryPropsTabsContextProvider.tsx
index fad140efd..4a58babcc 100644
--- a/src/renderer/hooks/EntryPropsTabsContextProvider.tsx
+++ b/src/renderer/hooks/EntryPropsTabsContextProvider.tsx
@@ -38,6 +38,7 @@ import { useSelector } from 'react-redux';
export type TabItem = {
icon: React.ReactNode;
title: string;
+ showBadge: boolean;
name: (typeof TabNames)[keyof typeof TabNames];
};
@@ -78,6 +79,23 @@ export const EntryPropsTabsContextProvider = ({
return location?.checkDirExist(backupPath);
}
+ function haveAIChat(openedEntry: TS.OpenedEntry): Promise<boolean> {
+ if (openedEntry.isFile) {
+ return Promise.resolve(false);
+ }
+ const location: CommonLocation = findLocation(openedEntry.locationID);
+ const dirSeparator = location
+ ? location.getDirSeparator()
+ : AppConfig.dirSeparator;
+ const aiChatPath =
+ openedEntry.path +
+ dirSeparator +
+ AppConfig.metaFolder +
+ dirSeparator +
+ AppConfig.aiFolder;
+ return location?.checkDirExist(aiChatPath);
+ }
+
function isEditable(openedEntry: TS.OpenedEntry): boolean {
if (openedEntry) {
const location: CommonLocation = findLocation(openedEntry.locationID);
@@ -94,6 +112,7 @@ export const EntryPropsTabsContextProvider = ({
const openedLocation: CommonLocation = findLocation(oEntry.locationID);
const tab1: TabItem = {
icon: <EntryPropertiesIcon />,
+ showBadge: false,
title: t('core:details'),
name: TabNames.propertiesTab,
};
@@ -104,6 +123,7 @@ export const EntryPropsTabsContextProvider = ({
) : (
<DescriptionIcon />
),
+ showBadge: Boolean(oEntry && oEntry.meta && oEntry.meta.description),
title: t('core:filePropertiesDescription'),
name: TabNames.descriptionTab,
};
@@ -113,6 +133,7 @@ export const EntryPropsTabsContextProvider = ({
if (revisions) {
const tab3: TabItem = {
icon: <RevisionIcon />,
+ showBadge: false,
title: t('core:revisions'),
name: TabNames.revisionsTab,
};
@@ -120,17 +141,18 @@ export const EntryPropsTabsContextProvider = ({
}
if ((oEntry && !oEntry.isFile) || (devMode && Pro)) {
- if (!openedLocation.isReadOnly) {
- const tab4: TabItem = {
- icon: <AIIcon />,
- title: oEntry.isFile ? t('core:aiSettingsTab') : t('core:aiChatTab'),
- name: TabNames.aiTab,
- };
- tabsArray.push(tab4);
- }
+ const aiChatAvailable = await haveAIChat(oEntry);
+ const tab4: TabItem = {
+ showBadge: aiChatAvailable,
+ icon: <AIIcon />,
+ title: oEntry.isFile ? t('core:aiSettingsTab') : t('core:aiChatTab'),
+ name: TabNames.aiTab,
+ };
+ tabsArray.push(tab4);
}
const tab5: TabItem = {
icon: <LinkIcon />,
+ showBadge: false,
title: t('core:links'),
name: TabNames.linksTab,
};