11import { BookTextIcon , MenuIcon } from '@/assets/Icons'
22import { Markdown } from '@/components'
3- import { useRepoContext } from '@/context/MacroContext '
3+ import { useMacros } from '@/hook/useVMacros '
44import {
55 Accordion ,
66 AccordionItem ,
@@ -11,7 +11,6 @@ import {
1111 Snippet ,
1212 Spinner
1313} from '@heroui/react'
14- import { useEffect , useMemo , useState } from 'react'
1514
1615const getBreadcrumbs = ( path : string ) =>
1716 path
@@ -23,55 +22,16 @@ const getBreadcrumbs = (path: string) =>
2322 ) )
2423
2524export default function Vmacros ( ) {
26- const { repoTree, isPending, error } = useRepoContext ( )
27- const [ selectedFilePath , setSelectedFilePath ] = useState < string | null > ( null )
28- const [ fileContent , setFileContent ] = useState < string > ( '' )
29- const [ searchTerm , setSearchTerm ] = useState < string > ( '' )
30-
31- useEffect ( ( ) => {
32- if ( selectedFilePath ) {
33- const file = repoTree . find ( ( item ) => item . path === selectedFilePath )
34- setFileContent ( file ?. mdContent || 'No hay contenido disponible para este archivo.' )
35- }
36- } , [ selectedFilePath , repoTree ] )
37-
38- const folders = useMemo ( ( ) => {
39- return repoTree . reduce <
40- Record < string , Record < string , { path : string ; mdContent : string | null } [ ] > >
41- > ( ( acc , item ) => {
42- if ( item . type === 'blob' && item . path . endsWith ( '.md' ) ) {
43- const parts = item . path . split ( '/' )
44- const folder = parts [ 0 ]
45- const subFolder = parts . length > 2 ? parts [ 1 ] : ''
46-
47- acc [ folder ] = acc [ folder ] || { }
48- acc [ folder ] [ subFolder ] = acc [ folder ] [ subFolder ] || [ ]
49- acc [ folder ] [ subFolder ] . push ( { path : item . path , mdContent : item . mdContent } )
50- }
51- return acc
52- } , { } )
53- } , [ repoTree ] )
54-
55- const filteredFolders = useMemo ( ( ) => {
56- if ( ! searchTerm ) return folders
57-
58- const lowerSearch = searchTerm . toLowerCase ( )
59- const result : typeof folders = { }
60-
61- for ( const [ folder , subfolders ] of Object . entries ( folders ) ) {
62- for ( const [ subfolder , files ] of Object . entries ( subfolders ) ) {
63- const filteredFiles = files . filter ( ( { path } ) =>
64- path . toLowerCase ( ) . includes ( lowerSearch )
65- )
66-
67- if ( filteredFiles . length > 0 ) {
68- if ( ! result [ folder ] ) result [ folder ] = { }
69- result [ folder ] [ subfolder ] = filteredFiles
70- }
71- }
72- }
73- return result
74- } , [ folders , searchTerm ] )
25+ const {
26+ isPending,
27+ error,
28+ selectedFilePath,
29+ setSelectedFilePath,
30+ fileContent,
31+ searchTerm,
32+ setSearchTerm,
33+ filteredFolders
34+ } = useMacros ( )
7535
7636 return (
7737 < div className = "flex h-screen" >
@@ -167,8 +127,7 @@ export default function Vmacros() {
167127 </ div >
168128 ) : (
169129 < p className = "" >
170- { repoTree . length } Vanilla Macros found, select a file to view its content or
171- create a new one.
130+ Vanilla Macros found, select a file to view its content or create a new one.
172131 </ p >
173132 ) }
174133 </ main >
0 commit comments