From 4479300027d9a724057aec1a465f6dcbc2e39205 Mon Sep 17 00:00:00 2001 From: danysmall Date: Wed, 12 Oct 2022 19:50:52 +0300 Subject: [PATCH] Fixed article entity bug --- src/article/data/articleAPIService.ts | 2 +- src/article/data/articleReducer.ts | 1 - src/article/domain/ArticleEntity.ts | 10 -- src/article/domain/articleEntity.ts | 8 +- src/article/domain/articleStore.ts | 3 +- .../useCases/params/create_article_params.ts | 2 +- .../ArticleInteractionButtons.tsx | 106 ++++++++---------- src/components/ArticleSearchResult.tsx | 2 +- src/components/SearchResultsSection.tsx | 2 +- src/components/fetchAnArticle/NotFound.tsx | 4 +- .../data/dto/searchResultsDTO.ts | 22 ++-- src/searchResults/data/searchService.ts | 18 ++- .../domain/searchResultsEntity.ts | 4 +- src/store/store.ts | 2 + 14 files changed, 91 insertions(+), 95 deletions(-) delete mode 100755 src/article/domain/ArticleEntity.ts diff --git a/src/article/data/articleAPIService.ts b/src/article/data/articleAPIService.ts index a217f5b..9936fd2 100644 --- a/src/article/data/articleAPIService.ts +++ b/src/article/data/articleAPIService.ts @@ -17,7 +17,7 @@ async function getArticle(id: string): Promise
{ const dto = response.data; return create({ id: dto.id, - topic: dto.topic, + topic: [dto.topic], title: dto.title, authors: dto.authors, tags: dto.tags, diff --git a/src/article/data/articleReducer.ts b/src/article/data/articleReducer.ts index 491e8f1..bdc5d45 100644 --- a/src/article/data/articleReducer.ts +++ b/src/article/data/articleReducer.ts @@ -1,5 +1,4 @@ import { AnyAction } from "@reduxjs/toolkit"; -import { Article } from "article/domain/articleEntity"; import type { ArticleStore } from "../domain/articleStore"; import * as actionTypes from "./articleActionTypes"; diff --git a/src/article/domain/ArticleEntity.ts b/src/article/domain/ArticleEntity.ts deleted file mode 100755 index 40aeff8..0000000 --- a/src/article/domain/ArticleEntity.ts +++ /dev/null @@ -1,10 +0,0 @@ -export interface Article { - id?: string; - title?: string; - authors?: string[]; - topic?: string[]; - summary?: string; - tags?: string[]; - content?: string; - publisher?: string; -} diff --git a/src/article/domain/articleEntity.ts b/src/article/domain/articleEntity.ts index 69e9520..bca093b 100644 --- a/src/article/domain/articleEntity.ts +++ b/src/article/domain/articleEntity.ts @@ -1,9 +1,9 @@ export interface Article { id: string; - topic: string; title: string; - authors: string[]; - tags: string[]; - summary: string; content: string; + topic?: string[]; + authors?: string[]; + tags?: string[]; + summary?: string; } diff --git a/src/article/domain/articleStore.ts b/src/article/domain/articleStore.ts index ad7e3f3..4ec1805 100644 --- a/src/article/domain/articleStore.ts +++ b/src/article/domain/articleStore.ts @@ -1,5 +1,4 @@ -import type { Article } from "./articleEntity"; - +import { Article } from './articleEntity'; interface ArticleStore { // State article: Article | undefined; diff --git a/src/article/useCases/params/create_article_params.ts b/src/article/useCases/params/create_article_params.ts index 49b5545..d56bb5c 100644 --- a/src/article/useCases/params/create_article_params.ts +++ b/src/article/useCases/params/create_article_params.ts @@ -1,6 +1,6 @@ export interface CreateArticleParams { id: string; - topic: string; + topic: string[]; title: string; authors: string[]; tags: string[]; diff --git a/src/components/Article/ArticleParts/InteractionButtons/ArticleInteractionButtons.tsx b/src/components/Article/ArticleParts/InteractionButtons/ArticleInteractionButtons.tsx index b8fd218..410d472 100755 --- a/src/components/Article/ArticleParts/InteractionButtons/ArticleInteractionButtons.tsx +++ b/src/components/Article/ArticleParts/InteractionButtons/ArticleInteractionButtons.tsx @@ -11,85 +11,77 @@ import { SVGFolder, } from "components/icons"; import classNames from "classnames"; +import { Transition } from "@headlessui/react"; -import { useArticleViewModel } from "article/controller/articleViewModel"; -import { useArticleStore } from "article/data/articleStoreImplementation"; -import { useParams } from "react-router"; -import Link from "components/typography/Link"; -import { getArticle } from "article/data/articleAPIService"; +const interactionButtonsStore = [ + { + icon: , + title: "Read file", + buttonEmphasis: "high", + iconClassName: "h-6 fill-white stroke-white", + }, + { + icon: , + title: "Download", + buttonEmphasis: "low", + iconClassName: "w-6 fill-gray-900 stroke-gray-900", + }, + { + icon: , + title: "Cite", + buttonEmphasis: "low", + iconClassName: "w-6 fill-gray-900 stroke-gray-900", + }, + { + icon: , + title: "Share", + buttonEmphasis: "low", + iconClassName: "w-6 fill-gray-900 stroke-gray-900", + }, +]; type ArticleButtonProps = { + isAbstractOpen?: boolean; + openAbstract?: () => void; children?: React.ReactNode; className?: string; emphasis?: "high" | "low"; } & Omit, "">; export function ArticleInteractionButtons({ + isAbstractOpen = false, children, + openAbstract = () => { }, className, - emphasis, //to change displaying of component + emphasis = "high", //to change displaying of component ...props }: ArticleButtonProps) { const abstractButton = ( - ); - const { id } = useParams(); - const newId = `${id}`; - const interactionButtonsStore = [ - { - icon: , - title: "Read file", - buttonEmphasis: "high", - iconClassName: "h-6 fill-white stroke-white", - dist: `${newId}/anarticlebody`, - }, - { - icon: , - title: "Download", - buttonEmphasis: "low", - iconClassName: "w-6 fill-gray-900 stroke-gray-900", - }, - { - icon: , - title: "Cite", - buttonEmphasis: "low", - iconClassName: "w-6 fill-gray-900 stroke-gray-900", - }, - { - icon: , - title: "Share", - buttonEmphasis: "low", - iconClassName: "w-6 fill-gray-900 stroke-gray-900", - }, - ]; - // + const fileInteractionButtons = interactionButtonsStore.map((button) => { return ( - getArticle(newId) : () => { } - } - to={button.dist} + - + + {React.cloneElement(button.icon, { className: button.iconClassName })} + + {emphasis === "high" ? {button.title} : null} + ); }); diff --git a/src/components/ArticleSearchResult.tsx b/src/components/ArticleSearchResult.tsx index e0c5f49..d06fd3a 100644 --- a/src/components/ArticleSearchResult.tsx +++ b/src/components/ArticleSearchResult.tsx @@ -1,6 +1,6 @@ import { useState } from "react"; import { Article } from "components/Article/Article"; -import { Article as ArticleTypes } from "article/domain/ArticleEntity"; +import { Article as ArticleTypes } from "article/domain/articleEntity"; import classNames from "classnames"; import { debounce } from "lodash"; import { useSearchStoreImplementation } from "searchResults/data/searchStoreImplementation"; diff --git a/src/components/SearchResultsSection.tsx b/src/components/SearchResultsSection.tsx index ca8fd64..dfa9b22 100644 --- a/src/components/SearchResultsSection.tsx +++ b/src/components/SearchResultsSection.tsx @@ -38,7 +38,7 @@ export const SearchResultSection = () => {
-
{ getResults()}
+
{getResults()}
); }; diff --git a/src/components/fetchAnArticle/NotFound.tsx b/src/components/fetchAnArticle/NotFound.tsx index 5db7e0d..f0a4728 100644 --- a/src/components/fetchAnArticle/NotFound.tsx +++ b/src/components/fetchAnArticle/NotFound.tsx @@ -1,7 +1,7 @@ import React from "react"; import Container from "components/Container"; import { Button } from "components/Button/Button"; -import Link from "components/Link"; +import Link from "components/typography/Link"; const NotFound = () => { return ( @@ -24,7 +24,7 @@ const NotFound = () => { bar ); diff --git a/src/searchResults/data/dto/searchResultsDTO.ts b/src/searchResults/data/dto/searchResultsDTO.ts index 679b8fd..b84b276 100755 --- a/src/searchResults/data/dto/searchResultsDTO.ts +++ b/src/searchResults/data/dto/searchResultsDTO.ts @@ -1,18 +1,20 @@ +import { Article } from "article/domain/articleEntity"; + export type SearchResultsDTO = { data: ArticleDTO[]; -meta: SearchResultsMeta; + meta: SearchResultsMeta; }; export type ArticleDTO = { - id?: string; - title?: string; - authors?: string[]; - topic?: string[]; - summary?: string; - tags?: string[]; - content?: string; + id: string; + title: string; + authors: string[]; + topic: string[]; + summary: string; + tags: string[]; + content: string; }; export type SearchResultsMeta = { - total: string; -} \ No newline at end of file + total: string; +} diff --git a/src/searchResults/data/searchService.ts b/src/searchResults/data/searchService.ts index 56448f4..dbf0cf6 100755 --- a/src/searchResults/data/searchService.ts +++ b/src/searchResults/data/searchService.ts @@ -10,11 +10,23 @@ const searchEndpoint = "/papers/search"; async function search(request: string): Promise { try { const response = await integratorApiClient.get( - searchEndpoint + `?query=` + request + `&limit=10&offset=0` - // "https://run.mocky.io/v3/ea705665-2479-4039-8b81-412e011fc145" + // searchEndpoint + `?query=` + request + `&limit=10&offset=0` + "https://run.mocky.io/v3/ea705665-2479-4039-8b81-412e011fc145" ); const dto = response.data; - return create({ data: dto.data, meta: dto.meta }); + return create({ + data: dto.data.map((e) => { + return { + authors: e.authors, + content: e.content, + id: e.id, + summary: e.summary, + tags: e.tags, + title: e.title, + topic: e.topic, + } + }), meta: dto.meta + }); } catch (reason) { if (axios.isAxiosError(reason)) { throw Failure.fromReason(reason, "failures.services.load"); diff --git a/src/searchResults/domain/searchResultsEntity.ts b/src/searchResults/domain/searchResultsEntity.ts index 516aad8..d55667a 100755 --- a/src/searchResults/domain/searchResultsEntity.ts +++ b/src/searchResults/domain/searchResultsEntity.ts @@ -1,8 +1,8 @@ -import { Article } from "article/domain/ArticleEntity"; +import { Article } from "article/domain/articleEntity"; export interface SearchResults { data: Article[]; - meta:SearchResultsMeta ; + meta: SearchResultsMeta; } export interface SearchResultsMeta { diff --git a/src/store/store.ts b/src/store/store.ts index 42d1918..bb1665f 100755 --- a/src/store/store.ts +++ b/src/store/store.ts @@ -1,10 +1,12 @@ import { configureStore } from "@reduxjs/toolkit"; +import { articleReducer } from "article/data/articleReducer"; import thunk from "redux-thunk"; import { searchResultReducer } from "searchResults/data/searchReducer"; const store = configureStore({ reducer: { searchResults: searchResultReducer, + article: articleReducer, }, middleware: [thunk], });