| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | import React, { useCallback, useEffect, useState } from 'react' |
| 2 | 2 | import { createContextHook } from '../utils/bootstrap' |
| 3 | 3 | import { isNetworkAdmin } from '../utils/screen' |
| 4 | +import { parseSnippetObject } from '../utils/snippets/objects' | |
| 4 | 5 | import { useSnippetsAPI } from './useSnippetsAPI' |
| 5 | 6 | import type { PropsWithChildren } from 'react' |
| 6 | 7 | import type { Snippet } from '../types/Snippet' |
| 7 | 8 | |
| @@ -13,9 +14,11 @@ | ||
| 13 | 14 | const [Context, useSnippetsList] = createContextHook<SnippetsListContext>('useSnippetsList') |
| 14 | 15 | |
| 15 | 16 | export const WithSnippetsListContext: React.FC<PropsWithChildren> = ({ children }) => { |
| 16 | 17 | const { fetchAll } = useSnippetsAPI() |
| 17 | - const [snippetsList, setSnippetsList] = useState<Snippet[]>() | |
| 18 | + const [snippetsList, setSnippetsList] = useState<Snippet[] | undefined>( | |
| 19 | + () => window.CODE_SNIPPETS_MANAGE?.snippetsList?.map(parseSnippetObject) | |
| 20 | + ) | |
| 18 | 21 | |
| 19 | 22 | const refreshSnippetsList = useCallback(async (): Promise<void> => { |
| 20 | 23 | try { |
| 21 | 24 | console.info('Fetching snippets list') |