Fixed 404 error on "article/info/$id" pages
This commit is contained in:
parent
fecce76fe1
commit
e20831fbfc
@ -1,6 +1,5 @@
|
|||||||
import type { ArticleStore } from "../domain/articleStore";
|
import type { ArticleStore } from "../domain/articleStore";
|
||||||
import { useCallback, useEffect } from "react";
|
import { useCallback, useEffect } from "react";
|
||||||
import { Article } from "article/domain/articleEntity";
|
|
||||||
import { GetArticleUseCase } from "article/useCases/getArticleUseCase";
|
import { GetArticleUseCase } from "article/useCases/getArticleUseCase";
|
||||||
import { FetchArticleUseCase } from "article/useCases/fetchArticleUseCase";
|
import { FetchArticleUseCase } from "article/useCases/fetchArticleUseCase";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
@ -12,15 +11,17 @@ function useArticleViewModel(
|
|||||||
) {
|
) {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
|
||||||
const getArticle = useCallback(
|
// const getArticle = useCallback(
|
||||||
() => {
|
// () => {
|
||||||
getArticleUseCase.call(id ?? '').catch((_) => fetchArticleUseCase.call(id ?? ''));
|
// getArticleUseCase.call(id ?? '').catch((_) => fetchArticleUseCase.call(id ?? ''));
|
||||||
console.log(id);
|
// console.log(id);
|
||||||
},
|
// },
|
||||||
[id]
|
// [id]
|
||||||
);
|
// );
|
||||||
|
|
||||||
useEffect(getArticle, []);
|
useEffect(() => {
|
||||||
|
getArticleUseCase.call(id ?? '').catch((_) => fetchArticleUseCase.call(id ?? ''));
|
||||||
|
}, []);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
article: store.currentArticle,
|
article: store.currentArticle,
|
||||||
|
@ -17,7 +17,7 @@ const articleReducer = (
|
|||||||
): ArticleStoreState => {
|
): ArticleStoreState => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case actionTypes.SET_ARTICLE:
|
case actionTypes.SET_ARTICLE:
|
||||||
return { ...state, articles: action.updatedList, currentArticle: action.article };
|
return { ...state, articles: action.updatedList, currentArticle: action.article, hasError: typeof action.article === undefined };
|
||||||
case actionTypes.GET_ARTICLE:
|
case actionTypes.GET_ARTICLE:
|
||||||
return { ...state, isLoading: true };
|
return { ...state, isLoading: true };
|
||||||
case actionTypes.GET_ARTICLE_SUCCESS:
|
case actionTypes.GET_ARTICLE_SUCCESS:
|
||||||
|
@ -26,17 +26,4 @@ class FetchArticleUseCase {
|
|||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const fetchArticleUseCase = async (
|
|
||||||
fetchArticleCallback: (id: string) => Promise<Article | null>,
|
|
||||||
setArticle: ArticleStore["setArticle"],
|
|
||||||
id: string,
|
|
||||||
): Promise<Article | null> => {
|
|
||||||
const article = await fetchArticleCallback(id);
|
|
||||||
if (article) {
|
|
||||||
await setArticle(article);
|
|
||||||
}
|
|
||||||
return article;
|
|
||||||
};
|
|
||||||
export { FetchArticleUseCase };
|
export { FetchArticleUseCase };
|
||||||
export { fetchArticleUseCase };
|
|
||||||
|
@ -22,18 +22,4 @@ class GetArticleUseCase {
|
|||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const getArticleUseCase = async (
|
|
||||||
getArticle: ArticleStore["getArticle"],
|
|
||||||
setArticle: ArticleStore["setArticle"],
|
|
||||||
id: Article["id"]
|
|
||||||
): Promise<Article | null> => {
|
|
||||||
const article = await getArticle(id);
|
|
||||||
if (article) {
|
|
||||||
await setArticle(article);
|
|
||||||
}
|
|
||||||
return article;
|
|
||||||
};
|
|
||||||
|
|
||||||
export { GetArticleUseCase };
|
export { GetArticleUseCase };
|
||||||
export { getArticleUseCase };
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user