feat(client): fix errors in the client about document slices

This commit is contained in:
perf3ct 2025-06-16 16:57:45 +00:00
parent 0e32d676af
commit de4ace5858
No known key found for this signature in database
GPG Key ID: 569C4EEC436F5232
3 changed files with 13 additions and 6 deletions

View File

@ -200,6 +200,9 @@ const StatsCard: React.FC<StatsCardProps> = ({ title, value, subtitle, icon: Ico
const RecentDocuments: React.FC<RecentDocumentsProps> = ({ documents = [] }) => {
const navigate = useNavigate();
const theme = useTheme();
// Ensure documents is always an array
const safeDocuments = Array.isArray(documents) ? documents : [];
const getFileIcon = (mimeType?: string): React.ComponentType<any> => {
if (mimeType?.includes('pdf')) return PdfIcon;
@ -270,7 +273,7 @@ const RecentDocuments: React.FC<RecentDocumentsProps> = ({ documents = [] }) =>
/>
</Box>
{documents.length === 0 ? (
{safeDocuments.length === 0 ? (
<Box sx={{ textAlign: 'center', py: 4 }}>
<Box sx={{
width: 64,
@ -298,7 +301,7 @@ const RecentDocuments: React.FC<RecentDocumentsProps> = ({ documents = [] }) =>
</Box>
) : (
<List sx={{ p: 0 }}>
{documents.slice(0, 5).map((doc, index) => {
{safeDocuments.slice(0, 5).map((doc, index) => {
const FileIconComponent = getFileIcon(doc.mime_type);
return (

View File

@ -275,8 +275,12 @@ const GlobalSearchBar: React.FC<GlobalSearchBarProps> = ({ sx, ...props }) => {
key={index}
component="mark"
sx={{
backgroundColor: 'primary.light',
color: 'primary.contrastText',
backgroundColor: theme.palette.mode === 'light'
? 'rgba(102, 126, 234, 0.2)'
: 'rgba(155, 181, 255, 0.25)',
color: theme.palette.mode === 'light'
? theme.palette.primary.dark
: theme.palette.primary.light,
padding: '0 2px',
borderRadius: '2px',
fontWeight: 600,
@ -288,7 +292,7 @@ const GlobalSearchBar: React.FC<GlobalSearchBarProps> = ({ sx, ...props }) => {
}
return part;
});
}, []);
}, [theme.palette.mode, theme.palette.primary]);
// Enhanced search with context snippets
const generateContextSnippet = useCallback((filename: string, searchTerm: string): string => {

View File

@ -807,7 +807,7 @@ const WebDAVTabContent: React.FC<WebDAVTabContentProps> = ({
</Typography>
)}
{syncStatus.errors && syncStatus.errors.length > 0 && (
{syncStatus.errors && Array.isArray(syncStatus.errors) && syncStatus.errors.length > 0 && (
<Alert severity="error" sx={{ mt: 2 }}>
<Typography variant="body2" sx={{ mb: 1 }}>
<strong>Recent Errors:</strong>