jam411 3 лет назад
Родитель
Сommit
0a1fcf17bd

+ 8 - 2
packages/app/src/components/Admin/PluginsExtension/PluginsExtensionPageContents.tsx

@@ -1,6 +1,6 @@
 import React from 'react';
 
-import { SearchResultItem } from '~/models/SearchResultItem';
+import { PluginItem } from '~/models/SearchResultItem';
 import { useInstalledPlugins } from '~/stores/useInstalledPlugins';
 
 import Loading from './Loading';
@@ -10,13 +10,19 @@ import { PluginInstallerForm } from './PluginInstallerForm';
 
 // TODO: i18n
 
+
 export const PluginsExtensionPageContents = (): JSX.Element => {
   // const { data, error } = useInstalledPlugins();
+  // const { data: data, error } = useSWRxPlugins(pageId, pageNumber);
 
   // if (data == null) {
   //   return <Loading />;
   // }
 
+  // data?.items.map((item: PluginItem) => {
+  //   return <PluginCard name={item.name} url={item.url} description={item.description} />;
+  // })}
+
   return (
     <div>
 
@@ -39,7 +45,7 @@ export const PluginsExtensionPageContents = (): JSX.Element => {
             <PluginCard
               name={'growi-plugin-theme-welcome-to-fumiya-room'}
               url={'https://github.com/weseek/growi-plugin-theme-welcome-to-fumiya-room'}
-              description={'Welcome to fumiya\'s room! This is very very "latest" design...'}
+              description={'Welcome to fumiya\'s room!'}
             />
             <PluginCard
               name={'growi-plugin-copy-code-to-clipboard'}

+ 5 - 1
packages/app/src/models/SearchResult.ts

@@ -1,7 +1,11 @@
-import { SearchResultItem } from './SearchResultItem';
+import { SearchResultItem, PluginItem } from './SearchResultItem';
 
 export type SearchResult = {
   total_count: number,
   imcomplete_results: boolean,
   items: SearchResultItem[];
 }
+
+export type PluginResult = {
+  items: PluginItem[];
+}

+ 6 - 0
packages/app/src/models/SearchResultItem.ts

@@ -13,3 +13,9 @@ export type SearchResultItem = {
   homepage: string,
   stargazersCount: number,
 }
+
+export type PluginItem = {
+  name: string,
+  url: string,
+  description: string,
+}

+ 4 - 0
packages/app/src/server/routes/apiv3/plugins-extention.ts

@@ -10,6 +10,10 @@ module.exports = (crowi: Crowi) => {
   const router = express.Router();
   const { pluginService } = crowi;
 
+  // router.get('/', async(req, res) => {
+
+  // });
+
   router.post('/', async(req: PluginInstallerFormRequest, res: ApiV3Response) => {
     if (pluginService == null) {
       return res.apiv3Err(400);

+ 62 - 0
packages/app/src/stores/plugin-test.tsx

@@ -0,0 +1,62 @@
+import { useCallback } from 'react';
+
+import {
+  HasObjectId,
+  IAttachment, Nullable, SWRResponseWithUtils, withUtils,
+} from '@growi/core';
+import useSWR, { SWRResponse } from 'swr';
+
+import { apiPost } from '~/client/util/apiv1-client';
+import { apiv3Get } from '~/client/util/apiv3-client';
+import { IResAttachmentList } from '~/interfaces/attachment';
+
+import { PluginResult } from '../models/SearchResult';
+
+
+const pluginsFetcher = () => {
+  return async() => {
+    const reqUrl = '/plugins-extention';
+    const data = await fetch(reqUrl).then(res => res.json());
+    return data.searchResult;
+  };
+};
+
+export const useSWRxPlugins = (): SWRResponse<PluginResult | null, Error> => {
+  return useSWR('/extention', pluginsFetcher());
+};
+
+
+// export const useSWRxPlugins = (): SWRResponseWithUtils<Util, IDataAttachmentList, Error> => {
+//   const shouldFetch = pageId != null && pageNumber != null;
+
+//   const fetcher = useCallback(async(endpoint, pageId, pageNumber) => {
+//     const res = await apiv3Get<IResAttachmentList>(endpoint, { pageId, pageNumber });
+//     const resAttachmentList = res.data;
+//     const { paginateResult } = resAttachmentList;
+//     return {
+//       attachments: paginateResult.docs,
+//       totalAttachments: paginateResult.totalDocs,
+//       limit: paginateResult.limit,
+//     };
+//   }, []);
+
+//   const swrResponse = useSWR(
+//     shouldFetch ? ['/attachment/list', pageId, pageNumber] : null,
+//     fetcher,
+//   );
+
+//   // Utils
+//   const remove = useCallback(async(body: { attachment_id: string }) => {
+//     const { mutate } = swrResponse;
+
+//     try {
+//       await apiPost('/attachments.remove', body);
+//       mutate();
+//     }
+//     catch (err) {
+//       throw err;
+//     }
+//   }, [swrResponse]);
+
+//   return withUtils<Util, IDataAttachmentList, Error>(swrResponse, { remove });
+// };