mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-24 12:44:18 +08:00
fix(workspace): sort daily memory by date and inline into file grid
- Sort daily memory list by filename (YYYY-MM-DD.md) instead of mtime so editing an older file no longer bumps it to the top - Move daily memory card inline with workspace MD file buttons - Shorten card description across all locales - Defer file creation until user actually saves (no empty file on create)
This commit is contained in:
@@ -106,8 +106,8 @@ pub async fn list_daily_memory_files() -> Result<Vec<DailyMemoryFileInfo>, Strin
|
||||
});
|
||||
}
|
||||
|
||||
// Sort by modified_at descending (newest first)
|
||||
files.sort_by(|a, b| b.modified_at.cmp(&a.modified_at));
|
||||
// Sort by filename descending (newest date first, YYYY-MM-DD.md)
|
||||
files.sort_by(|a, b| b.filename.cmp(&a.filename));
|
||||
|
||||
Ok(files)
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ const DailyMemoryPanel: React.FC<DailyMemoryPanelProps> = ({
|
||||
[t],
|
||||
);
|
||||
|
||||
// Create today's note
|
||||
// Create today's note (deferred — file is only persisted on save)
|
||||
const handleCreateToday = useCallback(async () => {
|
||||
const filename = getTodayFilename();
|
||||
// Check if already exists in the list
|
||||
@@ -110,16 +110,10 @@ const DailyMemoryPanel: React.FC<DailyMemoryPanelProps> = ({
|
||||
await openFile(filename);
|
||||
return;
|
||||
}
|
||||
// Create with empty content, then open
|
||||
try {
|
||||
await workspaceApi.writeDailyMemoryFile(filename, "");
|
||||
await loadFiles();
|
||||
await openFile(filename);
|
||||
} catch (err) {
|
||||
console.error("Failed to create daily memory file:", err);
|
||||
toast.error(t("workspace.dailyMemory.createFailed"));
|
||||
}
|
||||
}, [files, openFile, loadFiles, t]);
|
||||
// Open editor with empty content — no file created until user saves
|
||||
setEditingFile(filename);
|
||||
setContent("");
|
||||
}, [files, openFile]);
|
||||
|
||||
// Save current file
|
||||
const handleSave = useCallback(async () => {
|
||||
|
||||
@@ -119,16 +119,11 @@ const WorkspaceFilesPanel: React.FC = () => {
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* Daily Memory section */}
|
||||
<div className="mt-8">
|
||||
<h3 className="text-sm font-medium text-foreground mb-3">
|
||||
{t("workspace.dailyMemory.sectionTitle")}
|
||||
</h3>
|
||||
{/* Daily Memory — inline with workspace files */}
|
||||
<button
|
||||
onClick={() => setShowDailyMemory(true)}
|
||||
className="w-full flex items-start gap-3 p-4 rounded-xl border border-border bg-card hover:bg-accent/50 transition-colors text-left group"
|
||||
className="flex items-start gap-3 p-4 rounded-xl border border-border bg-card hover:bg-accent/50 transition-colors text-left group"
|
||||
>
|
||||
<div className="mt-0.5 text-muted-foreground group-hover:text-foreground transition-colors">
|
||||
<Calendar className="w-5 h-5" />
|
||||
|
||||
@@ -1171,7 +1171,7 @@
|
||||
"title": "Daily Memory",
|
||||
"sectionTitle": "Daily Memory",
|
||||
"cardTitle": "Daily Memory Files",
|
||||
"cardDescription": "Browse and manage daily memory notes (memory/YYYY-MM-DD.md)",
|
||||
"cardDescription": "Browse & manage daily memories",
|
||||
"createToday": "Today's Note",
|
||||
"empty": "No daily memory files yet",
|
||||
"loadFailed": "Failed to load daily memory files",
|
||||
|
||||
@@ -1171,7 +1171,7 @@
|
||||
"title": "デイリーメモリー",
|
||||
"sectionTitle": "デイリーメモリー",
|
||||
"cardTitle": "デイリーメモリーファイル",
|
||||
"cardDescription": "デイリーメモリーノートの閲覧と管理(memory/YYYY-MM-DD.md)",
|
||||
"cardDescription": "デイリーメモリーの閲覧・管理",
|
||||
"createToday": "今日のノート",
|
||||
"empty": "デイリーメモリーファイルはまだありません",
|
||||
"loadFailed": "デイリーメモリーファイルの読み込みに失敗しました",
|
||||
|
||||
@@ -1171,7 +1171,7 @@
|
||||
"title": "每日记忆",
|
||||
"sectionTitle": "每日记忆",
|
||||
"cardTitle": "每日记忆文件",
|
||||
"cardDescription": "浏览和管理每日记忆笔记(memory/YYYY-MM-DD.md)",
|
||||
"cardDescription": "浏览管理每日记忆",
|
||||
"createToday": "今日笔记",
|
||||
"empty": "暂无每日记忆文件",
|
||||
"loadFailed": "加载每日记忆文件失败",
|
||||
|
||||
Reference in New Issue
Block a user