Spaces:
Sleeping
Sleeping
Upload 61 files
Browse files- App.tsx +13 -5
- components/Card.tsx +6 -6
- components/MoveToFolderModal.tsx +6 -4
App.tsx
CHANGED
|
@@ -315,7 +315,7 @@ const App: React.FC = () => {
|
|
| 315 |
if (!!a.isPinned !== !!b.isPinned) return a.isPinned ? -1 : 1;
|
| 316 |
|
| 317 |
if (sortOrder === 'name') {
|
| 318 |
-
if (a.isFolder === b.isFolder) return a.title.localeCompare(b.title);
|
| 319 |
return a.isFolder ? -1 : 1;
|
| 320 |
}
|
| 321 |
if (sortOrder === 'updated') {
|
|
@@ -352,14 +352,16 @@ const App: React.FC = () => {
|
|
| 352 |
// Scoring function
|
| 353 |
const getScore = (item: DataItem) => {
|
| 354 |
let score = 0;
|
| 355 |
-
const title = item.title.toLowerCase();
|
| 356 |
-
const summary = item.summary.toLowerCase();
|
| 357 |
-
const tags = item.tags.map(t => t.toLowerCase());
|
|
|
|
| 358 |
|
| 359 |
validKeywords.forEach(keyword => {
|
| 360 |
if (title.includes(keyword)) score += 10;
|
| 361 |
else if (tags.some(t => t.includes(keyword))) score += 5;
|
| 362 |
else if (summary.includes(keyword)) score += 2;
|
|
|
|
| 363 |
});
|
| 364 |
|
| 365 |
return score;
|
|
@@ -376,9 +378,15 @@ const App: React.FC = () => {
|
|
| 376 |
allScored.forEach(entry => {
|
| 377 |
let currentItem = entry.item;
|
| 378 |
let valid = true;
|
|
|
|
| 379 |
|
| 380 |
// Trace up to find the ancestor that lives in currentFolderId
|
| 381 |
while (currentItem && (currentItem.parentId || null) !== currentFolderId) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 382 |
const parent = items.find(i => i.id === currentItem.parentId);
|
| 383 |
if (!parent) {
|
| 384 |
valid = false; // Broken link or orphaned item, ignore
|
|
@@ -413,7 +421,7 @@ const App: React.FC = () => {
|
|
| 413 |
if (a.score !== b.score) return b.score - a.score; // Higher score first
|
| 414 |
|
| 415 |
// Secondary sort based on user preference
|
| 416 |
-
if (sortOrder === 'name') return a.item.title.localeCompare(b.item.title);
|
| 417 |
if (sortOrder === 'updated') return (b.item.updatedAt || b.item.createdAt) - (a.item.updatedAt || a.item.createdAt);
|
| 418 |
if (sortOrder === 'created') return b.item.createdAt - a.item.createdAt;
|
| 419 |
return 0;
|
|
|
|
| 315 |
if (!!a.isPinned !== !!b.isPinned) return a.isPinned ? -1 : 1;
|
| 316 |
|
| 317 |
if (sortOrder === 'name') {
|
| 318 |
+
if (a.isFolder === b.isFolder) return (a.title || '').localeCompare(b.title || '');
|
| 319 |
return a.isFolder ? -1 : 1;
|
| 320 |
}
|
| 321 |
if (sortOrder === 'updated') {
|
|
|
|
| 352 |
// Scoring function
|
| 353 |
const getScore = (item: DataItem) => {
|
| 354 |
let score = 0;
|
| 355 |
+
const title = String(item.title || '').toLowerCase();
|
| 356 |
+
const summary = String(item.summary || '').toLowerCase();
|
| 357 |
+
const tags = Array.isArray(item.tags) ? item.tags.map(t => String(t || '').toLowerCase()) : [];
|
| 358 |
+
const content = String(item.content || '').toLowerCase();
|
| 359 |
|
| 360 |
validKeywords.forEach(keyword => {
|
| 361 |
if (title.includes(keyword)) score += 10;
|
| 362 |
else if (tags.some(t => t.includes(keyword))) score += 5;
|
| 363 |
else if (summary.includes(keyword)) score += 2;
|
| 364 |
+
else if (content.includes(keyword)) score += 1;
|
| 365 |
});
|
| 366 |
|
| 367 |
return score;
|
|
|
|
| 378 |
allScored.forEach(entry => {
|
| 379 |
let currentItem = entry.item;
|
| 380 |
let valid = true;
|
| 381 |
+
const seenIds = new Set<string>();
|
| 382 |
|
| 383 |
// Trace up to find the ancestor that lives in currentFolderId
|
| 384 |
while (currentItem && (currentItem.parentId || null) !== currentFolderId) {
|
| 385 |
+
if (seenIds.has(currentItem.id)) {
|
| 386 |
+
valid = false; // Circular reference detected
|
| 387 |
+
break;
|
| 388 |
+
}
|
| 389 |
+
seenIds.add(currentItem.id);
|
| 390 |
const parent = items.find(i => i.id === currentItem.parentId);
|
| 391 |
if (!parent) {
|
| 392 |
valid = false; // Broken link or orphaned item, ignore
|
|
|
|
| 421 |
if (a.score !== b.score) return b.score - a.score; // Higher score first
|
| 422 |
|
| 423 |
// Secondary sort based on user preference
|
| 424 |
+
if (sortOrder === 'name') return (a.item.title || '').localeCompare(b.item.title || '');
|
| 425 |
if (sortOrder === 'updated') return (b.item.updatedAt || b.item.createdAt) - (a.item.updatedAt || a.item.createdAt);
|
| 426 |
if (sortOrder === 'created') return b.item.createdAt - a.item.createdAt;
|
| 427 |
return 0;
|
components/Card.tsx
CHANGED
|
@@ -31,7 +31,6 @@ export const Card: React.FC<CardProps> = ({ item, onClick, isSelectable, isSelec
|
|
| 31 |
};
|
| 32 |
|
| 33 |
const rawTitle = (item.title || '').replace(/<[^>]*>?/gm, '').replace(/ /g, ' ');
|
| 34 |
-
const truncatedTitle = rawTitle.length > 33 ? rawTitle.substring(0, 33) + '...' : rawTitle;
|
| 35 |
|
| 36 |
if (item.isFolder) {
|
| 37 |
return (
|
|
@@ -62,9 +61,10 @@ export const Card: React.FC<CardProps> = ({ item, onClick, isSelectable, isSelec
|
|
| 62 |
</div>
|
| 63 |
<h3
|
| 64 |
style={{ fontSize: styleConfig.general.cardTitleSize }}
|
| 65 |
-
className="font-bold text-white group-hover:text-primary transition-colors
|
|
|
|
| 66 |
>
|
| 67 |
-
{
|
| 68 |
</h3>
|
| 69 |
</div>
|
| 70 |
);
|
|
@@ -95,7 +95,7 @@ export const Card: React.FC<CardProps> = ({ item, onClick, isSelectable, isSelec
|
|
| 95 |
</div>
|
| 96 |
)}
|
| 97 |
<div className="mb-1 flex-grow flex flex-col min-h-0">
|
| 98 |
-
<div className="flex items-start gap-2 mb-2">
|
| 99 |
{Icon && (
|
| 100 |
<div className="text-primary shrink-0 mt-0.5">
|
| 101 |
<Icon size={20} />
|
|
@@ -103,10 +103,10 @@ export const Card: React.FC<CardProps> = ({ item, onClick, isSelectable, isSelec
|
|
| 103 |
)}
|
| 104 |
<h3
|
| 105 |
style={{ fontSize: styleConfig.general.cardTitleSize }}
|
| 106 |
-
className="font-bold text-white leading-tight group-hover:text-primary transition-colors
|
| 107 |
title={rawTitle}
|
| 108 |
>
|
| 109 |
-
{
|
| 110 |
</h3>
|
| 111 |
</div>
|
| 112 |
<div
|
|
|
|
| 31 |
};
|
| 32 |
|
| 33 |
const rawTitle = (item.title || '').replace(/<[^>]*>?/gm, '').replace(/ /g, ' ');
|
|
|
|
| 34 |
|
| 35 |
if (item.isFolder) {
|
| 36 |
return (
|
|
|
|
| 61 |
</div>
|
| 62 |
<h3
|
| 63 |
style={{ fontSize: styleConfig.general.cardTitleSize }}
|
| 64 |
+
className="font-bold text-white group-hover:text-primary transition-colors truncate w-full px-2"
|
| 65 |
+
title={rawTitle}
|
| 66 |
>
|
| 67 |
+
{rawTitle}
|
| 68 |
</h3>
|
| 69 |
</div>
|
| 70 |
);
|
|
|
|
| 95 |
</div>
|
| 96 |
)}
|
| 97 |
<div className="mb-1 flex-grow flex flex-col min-h-0">
|
| 98 |
+
<div className="flex items-start gap-2 mb-2 w-full">
|
| 99 |
{Icon && (
|
| 100 |
<div className="text-primary shrink-0 mt-0.5">
|
| 101 |
<Icon size={20} />
|
|
|
|
| 103 |
)}
|
| 104 |
<h3
|
| 105 |
style={{ fontSize: styleConfig.general.cardTitleSize }}
|
| 106 |
+
className="font-bold text-white leading-tight group-hover:text-primary transition-colors truncate min-w-0"
|
| 107 |
title={rawTitle}
|
| 108 |
>
|
| 109 |
+
{rawTitle}
|
| 110 |
</h3>
|
| 111 |
</div>
|
| 112 |
<div
|
components/MoveToFolderModal.tsx
CHANGED
|
@@ -32,18 +32,20 @@ export const MoveToFolderModal: React.FC<MoveToFolderModalProps> = ({
|
|
| 32 |
const filteredFolders = useMemo(() => {
|
| 33 |
if (searchQuery.trim() !== '') {
|
| 34 |
return folders
|
| 35 |
-
.filter(f => f.title.toLowerCase().includes(searchQuery.toLowerCase()))
|
| 36 |
.map(f => ({ folder: f, depth: 0 }));
|
| 37 |
}
|
| 38 |
|
| 39 |
-
const buildTree = (parentId: string | null = null, depth: number = 0): { folder: DataItem, depth: number }[] => {
|
| 40 |
const children = folders.filter(f => (f.parentId || null) === parentId);
|
| 41 |
-
children.sort((a, b) => a.title.localeCompare(b.title));
|
| 42 |
|
| 43 |
let result: { folder: DataItem, depth: number }[] = [];
|
| 44 |
for (const child of children) {
|
|
|
|
|
|
|
| 45 |
result.push({ folder: child, depth });
|
| 46 |
-
result = result.concat(buildTree(child.id, depth + 1));
|
| 47 |
}
|
| 48 |
return result;
|
| 49 |
};
|
|
|
|
| 32 |
const filteredFolders = useMemo(() => {
|
| 33 |
if (searchQuery.trim() !== '') {
|
| 34 |
return folders
|
| 35 |
+
.filter(f => (f.title || '').toLowerCase().includes(searchQuery.toLowerCase()))
|
| 36 |
.map(f => ({ folder: f, depth: 0 }));
|
| 37 |
}
|
| 38 |
|
| 39 |
+
const buildTree = (parentId: string | null = null, depth: number = 0, seenIds = new Set<string>()): { folder: DataItem, depth: number }[] => {
|
| 40 |
const children = folders.filter(f => (f.parentId || null) === parentId);
|
| 41 |
+
children.sort((a, b) => (a.title || '').localeCompare(b.title || ''));
|
| 42 |
|
| 43 |
let result: { folder: DataItem, depth: number }[] = [];
|
| 44 |
for (const child of children) {
|
| 45 |
+
if (seenIds.has(child.id)) continue; // Prevent infinite loops
|
| 46 |
+
seenIds.add(child.id);
|
| 47 |
result.push({ folder: child, depth });
|
| 48 |
+
result = result.concat(buildTree(child.id, depth + 1, new Set(seenIds)));
|
| 49 |
}
|
| 50 |
return result;
|
| 51 |
};
|