Dev #3
No files matched your search
@@ -106,6 +106,9 @@ export const WorkspaceView: React.FC<WorkspaceViewProps> = ({
|
||||
const [workspaceTags, setWorkspaceTags] = useState<TagSummary[]>([]);
|
||||
const [isLoadingTag, setIsLoadingTag] = useState(false);
|
||||
const [tagSearchQuery, setTagSearchQuery] = useState('');
|
||||
const [tagNoteContent, setTagNoteContent] = useState('');
|
||||
const [tagNoteSaveState, setTagNoteSaveState] = useState<'saved' | 'saving'>('saved');
|
||||
const tagNoteSaveTimerRef = useRef<any>(null);
|
||||
|
||||
// Collapsible sidebar sections
|
||||
const [isPinnedCollapsed, setIsPinnedCollapsed] = useState(false);
|
||||
@@ -412,12 +415,18 @@ export const WorkspaceView: React.FC<WorkspaceViewProps> = ({
|
||||
|
||||
const openTagPage = async (tag: string) => {
|
||||
const clean = tag.replace(/^#/, '').toLowerCase();
|
||||
if (tagNoteSaveTimerRef.current) {
|
||||
clearTimeout(tagNoteSaveTimerRef.current);
|
||||
tagNoteSaveTimerRef.current = null;
|
||||
}
|
||||
setSelectedTag(clean);
|
||||
setWorkspaceMode('tags');
|
||||
setIsLoadingTag(true);
|
||||
try {
|
||||
const details = await api.getTagDetails(clean);
|
||||
setTagDetails(details);
|
||||
setTagNoteContent(details.noteContent || '');
|
||||
setTagNoteSaveState('saved');
|
||||
} catch (err) {
|
||||
console.error('Failed to load tag details', err);
|
||||
} finally {
|
||||
@@ -425,6 +434,40 @@ export const WorkspaceView: React.FC<WorkspaceViewProps> = ({
|
||||
}
|
||||
};
|
||||
|
||||
const handleTagNoteChange = (newContent: string) => {
|
||||
setTagNoteContent(newContent);
|
||||
if (!selectedTag) return;
|
||||
const targetTag = selectedTag;
|
||||
setTagNoteSaveState('saving');
|
||||
if (tagNoteSaveTimerRef.current) {
|
||||
clearTimeout(tagNoteSaveTimerRef.current);
|
||||
}
|
||||
tagNoteSaveTimerRef.current = setTimeout(async () => {
|
||||
try {
|
||||
await api.updateTagPageNote(targetTag, newContent);
|
||||
setTagDetails((prev) =>
|
||||
prev && prev.tag === targetTag ? { ...prev, noteContent: newContent } : prev
|
||||
);
|
||||
setTagNoteSaveState('saved');
|
||||
} catch (err) {
|
||||
console.error('Failed to save tag note', err);
|
||||
setTagNoteSaveState('saved');
|
||||
}
|
||||
}, 450);
|
||||
};
|
||||
|
||||
const handleExportTagMarkdown = () => {
|
||||
if (!selectedTag) return;
|
||||
const md = `# #${selectedTag}\n\n${tagNoteContent || ''}\n`;
|
||||
const blob = new Blob([md], { type: 'text/markdown;charset=utf-8' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `tag-${selectedTag}.md`;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
loadDocs(initialDocId);
|
||||
}, [initialDocId]);
|
||||
@@ -3605,23 +3648,26 @@ export const WorkspaceView: React.FC<WorkspaceViewProps> = ({
|
||||
<div className="space-y-4">
|
||||
{/* Header Toolbar */}
|
||||
<div className="p-4 panel-surface space-y-3 border border-border rounded-card">
|
||||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||
<div className="flex items-center gap-2">
|
||||
{selectedTag ? (
|
||||
<>
|
||||
{selectedTag && (
|
||||
<div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setSelectedTag(null)}
|
||||
className="btn-action h-8 px-2.5 text-xs flex items-center gap-1.5"
|
||||
className="inline-flex items-center gap-1 text-[11px] font-medium text-muted hover:text-accent transition-colors cursor-pointer"
|
||||
title="Zurück zur Themen-Übersicht"
|
||||
>
|
||||
<ArrowLeft className="w-3.5 h-3.5 text-accent" />
|
||||
<ArrowLeft className="w-3 h-3 text-accent" />
|
||||
<span>Alle Themen</span>
|
||||
</button>
|
||||
<div className="h-4 w-px bg-border" />
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="w-8 h-8 rounded-lg bg-blue-500/10 border border-blue-500/30 flex items-center justify-center text-blue-500 dark:text-blue-400 font-bold">
|
||||
<Hash className="w-4 h-4" />
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||
<div className="flex items-center gap-2.5">
|
||||
{selectedTag ? (
|
||||
<>
|
||||
<div className="w-9 h-9 rounded-lg bg-blue-500/10 border border-blue-500/30 flex items-center justify-center text-blue-500 dark:text-blue-400 font-bold flex-shrink-0">
|
||||
<Hash className="w-5 h-5" />
|
||||
</div>
|
||||
<div>
|
||||
<h2 className="text-base font-bold text-main leading-tight flex items-center gap-1.5">
|
||||
@@ -3637,11 +3683,10 @@ export const WorkspaceView: React.FC<WorkspaceViewProps> = ({
|
||||
}`}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div className="flex items-center gap-2.5">
|
||||
<div className="w-9 h-9 rounded-lg bg-accent/10 border border-accent/30 flex items-center justify-center text-accent">
|
||||
<>
|
||||
<div className="w-9 h-9 rounded-lg bg-accent/10 border border-accent/30 flex items-center justify-center text-accent flex-shrink-0">
|
||||
<Hash className="w-5 h-5" />
|
||||
</div>
|
||||
<div>
|
||||
@@ -3650,7 +3695,7 @@ export const WorkspaceView: React.FC<WorkspaceViewProps> = ({
|
||||
{workspaceTags.length} {workspaceTags.length === 1 ? 'Thema' : 'Themen'} im gesamten Workspace
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -3760,12 +3805,66 @@ export const WorkspaceView: React.FC<WorkspaceViewProps> = ({
|
||||
<Sparkles className="w-6 h-6 animate-spin mx-auto mb-2 text-accent" />
|
||||
Hashtag-Verknüpfungen werden geladen…
|
||||
</div>
|
||||
) : !tagDetails || tagDetails.documents.length === 0 ? (
|
||||
<div className="p-12 text-center text-muted text-xs panel-surface space-y-2">
|
||||
<Hash className="w-8 h-8 mx-auto text-faint" />
|
||||
<p className="font-medium text-main">Keine Bullet Points mit #{selectedTag} gefunden</p>
|
||||
) : (
|
||||
<div className="space-y-4">
|
||||
{/* Dedicated Logseq-Style Hashtag Markdown Note Card (#tag.md) */}
|
||||
<div className="panel-surface p-4 space-y-2.5 border border-border rounded-card">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2 pb-2 border-b border-border">
|
||||
<div className="flex items-center gap-2">
|
||||
<FileText className="w-3.5 h-3.5 text-accent" />
|
||||
<span className="text-xs font-bold text-main">
|
||||
Eigene Notiz zu #{selectedTag}
|
||||
</span>
|
||||
<span className="badge-neutral text-[10px] font-mono">
|
||||
#{selectedTag}.md
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-[10px] text-faint font-mono">
|
||||
{tagNoteSaveState === 'saving' ? 'Speichert…' : 'Gespeichert'}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleExportTagMarkdown}
|
||||
className="btn-action h-6 px-2 text-[11px] flex items-center gap-1"
|
||||
title={`#${selectedTag}.md herunterladen`}
|
||||
>
|
||||
<Download className="w-3 h-3" />
|
||||
<span>.md</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<textarea
|
||||
value={tagNoteContent}
|
||||
onChange={(e) => handleTagNoteChange(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Tab') {
|
||||
e.preventDefault();
|
||||
const target = e.currentTarget;
|
||||
const start = target.selectionStart;
|
||||
const end = target.selectionEnd;
|
||||
const nextVal =
|
||||
tagNoteContent.slice(0, start) + ' ' + tagNoteContent.slice(end);
|
||||
handleTagNoteChange(nextVal);
|
||||
requestAnimationFrame(() => {
|
||||
target.setSelectionRange(start + 2, start + 2);
|
||||
});
|
||||
}
|
||||
}}
|
||||
rows={Math.max(4, tagNoteContent.split('\n').length + 1)}
|
||||
placeholder={`Eigene Gedanken, Zusammenfassungen oder Markdown-Notizen direkt zum Thema #${selectedTag} festhalten (unabhängig von den anderen Workspace-Notizen)…`}
|
||||
className="w-full bg-canvas/50 border border-border/60 rounded-card p-3 text-xs text-main leading-relaxed focus:outline-none focus:border-accent resize-y placeholder:text-faint"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Linked References / Verknüpfte Bullet Points from Workspace Notes */}
|
||||
{!tagDetails || tagDetails.documents.length === 0 ? (
|
||||
<div className="p-10 text-center text-muted text-xs panel-surface space-y-2 border border-border rounded-card">
|
||||
<Hash className="w-7 h-7 mx-auto text-faint" />
|
||||
<p className="font-medium text-main">Keine verknüpften Bullet Points mit #{selectedTag} in anderen Notizen</p>
|
||||
<p className="text-xs text-faint">
|
||||
Füge einfach in irgendeiner Notiz <code className="text-accent">#{selectedTag}</code> in einen Bullet Point ein.
|
||||
Füge einfach in irgendeiner Notiz <code className="text-accent">#{selectedTag}</code> in einen Bullet Point ein, damit er hier automatisch verknüpft wird.
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
@@ -3905,6 +4004,8 @@ export const WorkspaceView: React.FC<WorkspaceViewProps> = ({
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ===================================================================== */}
|
||||
{/* DOCUMENT SHARING MODAL */}
|
||||
|
||||
@@ -442,6 +442,20 @@ export const api = {
|
||||
};
|
||||
},
|
||||
|
||||
async updateTagPageNote(
|
||||
tag: string,
|
||||
content: string
|
||||
): Promise<{ tag: string; content: string; updatedAt: string }> {
|
||||
const clean = encodeURIComponent(tag.replace(/^#/, ''));
|
||||
return request<{ tag: string; content: string; updatedAt: string }>(
|
||||
`/api/v1/workspace/tags/${clean}/note`,
|
||||
{
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({ content }),
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
// --- WORKSPACE DOCUMENTS ---
|
||||
async getDocuments(): Promise<Document[]> {
|
||||
const res = await request<Document[]>('/api/v1/documents');
|
||||
|
||||
@@ -223,6 +223,8 @@ export interface TagDocumentGroup {
|
||||
|
||||
export interface TagDetails {
|
||||
tag: string;
|
||||
noteContent?: string;
|
||||
noteUpdatedAt?: string;
|
||||
documents: TagDocumentGroup[];
|
||||
totalMatches: number;
|
||||
}
|
||||
|
||||
@@ -106,6 +106,7 @@ func (s *Server) Router() http.Handler {
|
||||
// Workspace Tags & Pages
|
||||
r.Get("/api/v1/workspace/tags", s.handleGetWorkspaceTags)
|
||||
r.Get("/api/v1/workspace/tags/{tag}", s.handleGetTagDetails)
|
||||
r.Put("/api/v1/workspace/tags/{tag}/note", s.handleUpdateTagPageNote)
|
||||
|
||||
r.Get("/api/v1/documents", s.handleGetDocuments)
|
||||
r.Post("/api/v1/documents", s.handleCreateDocument)
|
||||
@@ -903,6 +904,28 @@ func (s *Server) handleGetTagDetails(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusOK, details)
|
||||
}
|
||||
|
||||
func (s *Server) handleUpdateTagPageNote(w http.ResponseWriter, r *http.Request) {
|
||||
userID := auth.GetUserID(r.Context())
|
||||
tag := chi.URLParam(r, "tag")
|
||||
var req struct {
|
||||
Content string `json:"content"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
writeError(w, http.StatusBadRequest, "Ungültiges JSON")
|
||||
return
|
||||
}
|
||||
updatedAt, err := s.store.UpdateTagPageNote(userID, tag, req.Content)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]string{
|
||||
"tag": tag,
|
||||
"content": req.Content,
|
||||
"updatedAt": updatedAt,
|
||||
})
|
||||
}
|
||||
|
||||
// --- DOCUMENT SHARING & COLLABORATION ---
|
||||
|
||||
func (s *Server) handleGetDocShares(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -315,6 +315,8 @@ type TagDocumentGroup struct {
|
||||
|
||||
type TagDetails struct {
|
||||
Tag string `json:"tag"`
|
||||
NoteContent string `json:"noteContent"`
|
||||
NoteUpdatedAt string `json:"noteUpdatedAt,omitempty"`
|
||||
Documents []TagDocumentGroup `json:"documents"`
|
||||
TotalMatches int `json:"totalMatches"`
|
||||
}
|
||||
|
||||
@@ -249,6 +249,14 @@ func (s *Store) migrate() error {
|
||||
CREATE INDEX IF NOT EXISTS idx_doc_block_tags_user_tag ON doc_block_tags(user_id, tag);
|
||||
CREATE INDEX IF NOT EXISTS idx_doc_block_tags_doc ON doc_block_tags(doc_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS tag_pages (
|
||||
user_id TEXT NOT NULL,
|
||||
tag TEXT NOT NULL,
|
||||
content TEXT NOT NULL DEFAULT '',
|
||||
updated_at TEXT NOT NULL,
|
||||
PRIMARY KEY(user_id, tag)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS lists (
|
||||
id TEXT PRIMARY KEY,
|
||||
space_id TEXT NOT NULL,
|
||||
@@ -1577,6 +1585,41 @@ func (s *Store) indexDocBlockTags(docID, userID string, blocks []domain.Document
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Store) saveTagPageToDisk(userID, tag, content string) {
|
||||
if s.docDir == "" || tag == "" {
|
||||
return
|
||||
}
|
||||
tagDir := filepath.Join(filepath.Dir(s.docDir), "tag_pages", userID)
|
||||
_ = os.MkdirAll(tagDir, 0755)
|
||||
safeTag := regexp.MustCompile(`[^a-zA-Z0-9äöüÄÖÜß_-]+`).ReplaceAllString(tag, "_")
|
||||
targetPath := filepath.Join(tagDir, safeTag+".md")
|
||||
if strings.TrimSpace(content) == "" {
|
||||
_ = os.Remove(targetPath)
|
||||
return
|
||||
}
|
||||
md := fmt.Sprintf("# #%s\n\n%s\n", tag, content)
|
||||
_ = os.WriteFile(targetPath, []byte(md), 0644)
|
||||
}
|
||||
|
||||
func (s *Store) UpdateTagPageNote(userID, tag, content string) (string, error) {
|
||||
cleanTag := strings.ToLower(strings.TrimPrefix(strings.TrimSpace(tag), "#"))
|
||||
if cleanTag == "" {
|
||||
return "", errors.New("tag name required")
|
||||
}
|
||||
now := domain.NowISO()
|
||||
_, err := s.db.Exec(
|
||||
`INSERT INTO tag_pages (user_id, tag, content, updated_at)
|
||||
VALUES (?, ?, ?, ?)
|
||||
ON CONFLICT(user_id, tag) DO UPDATE SET content = excluded.content, updated_at = excluded.updated_at`,
|
||||
userID, cleanTag, content, now,
|
||||
)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
s.saveTagPageToDisk(userID, cleanTag, content)
|
||||
return now, nil
|
||||
}
|
||||
|
||||
func (s *Store) GetWorkspaceTags(userID string) ([]domain.TagSummary, error) {
|
||||
rows, err := s.db.Query(
|
||||
`SELECT t.tag, COUNT(DISTINCT t.doc_id || ':' || t.block_id) as count
|
||||
@@ -1595,12 +1638,32 @@ func (s *Store) GetWorkspaceTags(userID string) ([]domain.TagSummary, error) {
|
||||
defer rows.Close()
|
||||
|
||||
results := make([]domain.TagSummary, 0)
|
||||
seen := make(map[string]bool)
|
||||
for rows.Next() {
|
||||
var ts domain.TagSummary
|
||||
if err := rows.Scan(&ts.Tag, &ts.Count); err == nil {
|
||||
results = append(results, ts)
|
||||
seen[ts.Tag] = true
|
||||
}
|
||||
}
|
||||
_ = rows.Close()
|
||||
|
||||
// Also include tags that have a non-empty tag_pages note even if not currently used in a block
|
||||
pageRows, err := s.db.Query(
|
||||
`SELECT tag FROM tag_pages WHERE user_id = ? AND TRIM(content) != '' ORDER BY tag ASC`,
|
||||
userID,
|
||||
)
|
||||
if err == nil {
|
||||
for pageRows.Next() {
|
||||
var t string
|
||||
if err := pageRows.Scan(&t); err == nil && t != "" && !seen[t] {
|
||||
results = append(results, domain.TagSummary{Tag: t, Count: 0})
|
||||
seen[t] = true
|
||||
}
|
||||
}
|
||||
_ = pageRows.Close()
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
@@ -1610,6 +1673,12 @@ func (s *Store) GetTagDetails(userID, tag string) (*domain.TagDetails, error) {
|
||||
return &domain.TagDetails{Tag: "", Documents: []domain.TagDocumentGroup{}, TotalMatches: 0}, nil
|
||||
}
|
||||
|
||||
var noteContent, noteUpdatedAt string
|
||||
_ = s.db.QueryRow(
|
||||
`SELECT content, updated_at FROM tag_pages WHERE user_id = ? AND tag = ?`,
|
||||
userID, cleanTag,
|
||||
).Scan(¬eContent, ¬eUpdatedAt)
|
||||
|
||||
rows, err := s.db.Query(
|
||||
`SELECT t.block_id, d.id, d.title, d.icon, d.folder_path, d.blocks_json, d.updated_at, d.user_id,
|
||||
COALESCE(u.display_name, '') as owner_name,
|
||||
@@ -1735,6 +1804,8 @@ func (s *Store) GetTagDetails(userID, tag string) (*domain.TagDetails, error) {
|
||||
|
||||
return &domain.TagDetails{
|
||||
Tag: cleanTag,
|
||||
NoteContent: noteContent,
|
||||
NoteUpdatedAt: noteUpdatedAt,
|
||||
Documents: docGroups,
|
||||
TotalMatches: totalMatches,
|
||||
}, nil
|
||||
|
||||
Reference in new issue
Block a user