1
1
import { BookTextIcon , MenuIcon } from '@/assets/Icons'
2
2
import { Markdown } from '@/components'
3
- import { useRepoContext } from '@/context/MacroContext '
3
+ import { useMacros } from '@/hook/useVMacros '
4
4
import {
5
5
Accordion ,
6
6
AccordionItem ,
@@ -11,7 +11,6 @@ import {
11
11
Snippet ,
12
12
Spinner
13
13
} from '@heroui/react'
14
- import { useEffect , useMemo , useState } from 'react'
15
14
16
15
const getBreadcrumbs = ( path : string ) =>
17
16
path
@@ -23,55 +22,16 @@ const getBreadcrumbs = (path: string) =>
23
22
) )
24
23
25
24
export 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 ( )
75
35
76
36
return (
77
37
< div className = "flex h-screen" >
@@ -167,8 +127,7 @@ export default function Vmacros() {
167
127
</ div >
168
128
) : (
169
129
< 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.
172
131
</ p >
173
132
) }
174
133
</ main >
0 commit comments