PluginProbe
Code Snippets / trunk
Code Snippets vtrunk
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
← All changes | js/hooks/useSnippetsList.tsx +4 -1 4.0.0-beta.1 → trunk View file →
@@ -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')