1+ 'use client'
2+
13import { useEffect , useState } from 'react'
24import { DashboardHero } from '../../Heros/DashboardHero/DashboardHero'
35import type { KnowledgeDocument , KnowledgeContext , Knowledge , TeamKnowledgeContext } from '../types'
@@ -32,6 +34,10 @@ export default function KnowledgeView({
3234 const [ isAddKnowledgeModalOpen , setIsAddKnowledgeModalOpen ] = useState ( false )
3335 const [ isAddTeamContextModalOpen , setIsAddTeamContextModalOpen ] = useState ( false )
3436
37+ useEffect ( ( ) => {
38+ if ( ! activeContext && contexts && contexts . length > 0 ) setActiveContext ( contexts [ 0 ] )
39+ } , [ contexts ] )
40+
3541 const handleAddKnowledge = ( knowledge : Omit < Knowledge , 'id' > ) => {
3642 if ( onAddKnowledge ) {
3743 onAddKnowledge ( knowledge )
@@ -46,32 +52,81 @@ export default function KnowledgeView({
4652 setIsAddTeamContextModalOpen ( false )
4753 }
4854
49- const Hero = ( ) => (
50- < DashboardHero
51- title = "Knowledge"
52- description = "Access, manage, and share all your team knowledge in one place."
53- gradient = "bg-gradient-to-r from-teal-600 via-cyan-600 to-blue-600"
54- primaryAction = {
55- onAddKnowledge
56- ? {
57- label : 'Create' ,
58- onClick : ( ) => setIsAddKnowledgeModalOpen ( true ) ,
59- }
60- : undefined
61- }
62- secondaryAction = {
63- onAddTeamContext
64- ? {
65- label : 'Add Context' ,
66- onClick : ( ) => setIsAddTeamContextModalOpen ( true ) ,
67- }
68- : undefined
69- }
70- />
71- )
55+ return (
56+ < div className = "flex flex-col h-full max-h-[calc(100vh-8rem)]" >
57+ < div className = "px-2 md:px-4 py-4 flex-shrink-0" >
58+ < DashboardHero
59+ title = "Knowledge"
60+ description = "Access, manage, and share all your team knowledge in one place."
61+ gradient = "bg-gradient-to-r from-teal-600 via-cyan-600 to-blue-600"
62+ primaryAction = {
63+ onAddKnowledge
64+ ? {
65+ label : 'Create' ,
66+ onClick : ( ) => setIsAddKnowledgeModalOpen ( true ) ,
67+ }
68+ : undefined
69+ }
70+ secondaryAction = {
71+ onAddTeamContext
72+ ? {
73+ label : 'Add Context' ,
74+ onClick : ( ) => setIsAddTeamContextModalOpen ( true ) ,
75+ }
76+ : undefined
77+ }
78+ />
79+
80+ { /* Context Tabs */ }
81+ { contexts && contexts . length > 0 && (
82+ < div className = "mt-6" >
83+ < div className = "border-b border-border" >
84+ < nav className = "-mb-px flex space-x-8 overflow-x-auto" >
85+ { contexts . map ( ( context ) => (
86+ < button
87+ key = { context . id }
88+ onClick = { ( ) => setActiveContext ( context ) }
89+ className = { `group inline-flex items-center gap-2 py-3 px-1 border-b-2 font-medium text-sm whitespace-nowrap transition-colors ${
90+ activeContext ?. id === context . id
91+ ? 'border-primary text-primary'
92+ : 'border-transparent text-muted-foreground hover:text-foreground hover:border-muted-foreground'
93+ } `}
94+ >
95+ { context . icon }
96+ { context . label }
97+ </ button >
98+ ) ) }
99+ </ nav >
100+ </ div >
72101
73- const Modals = ( ) => {
74- return (
102+ { /* Active Context Description */ }
103+ { activeContext ?. description && (
104+ < div className = "mt-3 px-1" >
105+ < p className = "text-sm text-muted-foreground" > { activeContext ?. description } </ p >
106+ </ div >
107+ ) }
108+ </ div >
109+ ) }
110+ </ div >
111+
112+ { activeContext ? (
113+ < div className = "flex-1 min-h-0 px-2 md:px-4 pb-4" >
114+ < div className = "h-full rounded-3xl border overflow-hidden" >
115+ < KnowledgeBrowser
116+ documents = { documents }
117+ menuConfig = { activeContext ?. menuConfig }
118+ onDocumentClick = { onDocumentClick }
119+ onDocumentShare = { onDocumentShare }
120+ selectedDocumentId = { selectedDocumentId }
121+ onDocumentUpdate = { onDocumentUpdate }
122+ />
123+ </ div >
124+ </ div >
125+ ) : (
126+ < div className = "flex-1 min-h-0 px-2 md:px-4 pb-4 flex items-center justify-center" >
127+ < p className = "text-muted-foreground" > No contexts available</ p >
128+ </ div >
129+ ) }
75130 < >
76131 < AddTeamContext
77132 isOpen = { isAddTeamContextModalOpen }
@@ -86,72 +141,6 @@ export default function KnowledgeView({
86141 knowledgeContexts = { contexts }
87142 />
88143 </ >
89- )
90- }
91-
92- // Return early if no contexts are provided
93- if ( ! contexts || contexts . length === 0 ) {
94- return (
95- < div className = "flex flex-col h-full max-h-[calc(100vh-8rem)]" >
96- < div className = "px-2 md:px-4 py-4 flex-shrink-0" >
97- < Hero />
98- </ div >
99- < div className = "flex-1 min-h-0 px-2 md:px-4 pb-4 flex items-center justify-center" >
100- < p className = "text-muted-foreground" > No contexts available</ p >
101- </ div >
102- < Modals />
103- </ div >
104- )
105- }
106-
107- return (
108- < div className = "flex flex-col h-full max-h-[calc(100vh-8rem)]" >
109- < div className = "px-2 md:px-4 py-4 flex-shrink-0" >
110- < Hero />
111-
112- { /* Context Tabs */ }
113- < div className = "mt-6" >
114- < div className = "border-b border-border" >
115- < nav className = "-mb-px flex space-x-8 overflow-x-auto" >
116- { contexts . map ( ( context ) => (
117- < button
118- key = { context . id }
119- onClick = { ( ) => setActiveContext ( context ) }
120- className = { `group inline-flex items-center gap-2 py-3 px-1 border-b-2 font-medium text-sm whitespace-nowrap transition-colors ${
121- activeContext . id === context . id
122- ? 'border-primary text-primary'
123- : 'border-transparent text-muted-foreground hover:text-foreground hover:border-muted-foreground'
124- } `}
125- >
126- { context . icon }
127- { context . label }
128- </ button >
129- ) ) }
130- </ nav >
131- </ div >
132-
133- { /* Active Context Description */ }
134- { activeContext . description && (
135- < div className = "mt-3 px-1" >
136- < p className = "text-sm text-muted-foreground" > { activeContext . description } </ p >
137- </ div >
138- ) }
139- </ div >
140- </ div >
141-
142- < div className = "flex-1 min-h-0 px-2 md:px-4 pb-4" >
143- < div className = "h-full rounded-3xl border overflow-hidden" >
144- < KnowledgeBrowser
145- documents = { documents }
146- menuConfig = { activeContext . menuConfig }
147- onDocumentClick = { onDocumentClick }
148- onDocumentShare = { onDocumentShare }
149- selectedDocumentId = { selectedDocumentId }
150- onDocumentUpdate = { onDocumentUpdate }
151- />
152- </ div >
153- </ div >
154- < Modals />
155144 </ div >
156145 )
157146}
0 commit comments