Skip to content

Commit

Permalink
home template
Browse files Browse the repository at this point in the history
  • Loading branch information
YukiOnishi1129 committed Jul 9, 2024
1 parent de33854 commit c6ef8ec
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 27 deletions.
8 changes: 4 additions & 4 deletions web/client/src/app/company/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { redirect } from "next/navigation";
import { Suspense } from "react";

import { HomeTemplate } from "@/features/home/components/HomeTemplate";
import { ArticleTemplate } from "@/features/articles/components/ArticleTemplate";
import { getUser } from "@/features/users/actions/user";

import { ScreenLoader } from "@/components/layout/ScreenLoader";
Expand All @@ -21,7 +21,7 @@ export default async function CompanyPage({ searchParams }: PageProps) {
const languageStatus =
typeof searchParams["languageStatus"] === "string"
? (parseInt(searchParams["languageStatus"]) as LanguageStatus)
: 1;
: 2;

const keyword =
typeof searchParams["keyword"] === "string"
Expand All @@ -45,11 +45,11 @@ export default async function CompanyPage({ searchParams }: PageProps) {
return (
<>
<Suspense fallback={<ScreenLoader />}>
<HomeTemplate
<ArticleTemplate
languageStatus={languageStatus}
keyword={keyword}
platformIdList={platformIdList}
tab={tab}
tab={"company"}
/>
</Suspense>
</>
Expand Down
11 changes: 4 additions & 7 deletions web/client/src/app/site/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { redirect } from "next/navigation";
import { Suspense } from "react";

import { HomeTemplate } from "@/features/home/components/HomeTemplate";
import { ArticleTemplate } from "@/features/articles/components/ArticleTemplate";
import { getUser } from "@/features/users/actions/user";

import { ScreenLoader } from "@/components/layout/ScreenLoader";
Expand All @@ -21,7 +21,7 @@ export default async function SitePage({ searchParams }: PageProps) {
const languageStatus =
typeof searchParams["languageStatus"] === "string"
? (parseInt(searchParams["languageStatus"]) as LanguageStatus)
: 1;
: 2;

const keyword =
typeof searchParams["keyword"] === "string"
Expand All @@ -39,17 +39,14 @@ export default async function SitePage({ searchParams }: PageProps) {
if (typeof searchParams["platformId"] === "string")
platformIdList.push(searchParams["platformId"]);

const tab =
typeof searchParams["tab"] === "string" ? searchParams["tab"] : "trend";

return (
<>
<Suspense fallback={<ScreenLoader />}>
<HomeTemplate
<ArticleTemplate
languageStatus={languageStatus}
keyword={keyword}
platformIdList={platformIdList}
tab={tab}
tab={"site"}
/>
</Suspense>
</>
Expand Down
11 changes: 4 additions & 7 deletions web/client/src/app/summary/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { redirect } from "next/navigation";
import { Suspense } from "react";

import { HomeTemplate } from "@/features/home/components/HomeTemplate";
import { ArticleTemplate } from "@/features/articles/components/ArticleTemplate";
import { getUser } from "@/features/users/actions/user";

import { ScreenLoader } from "@/components/layout/ScreenLoader";
Expand All @@ -21,7 +21,7 @@ export default async function SummaryPage({ searchParams }: PageProps) {
const languageStatus =
typeof searchParams["languageStatus"] === "string"
? (parseInt(searchParams["languageStatus"]) as LanguageStatus)
: 1;
: 2;

const keyword =
typeof searchParams["keyword"] === "string"
Expand All @@ -39,17 +39,14 @@ export default async function SummaryPage({ searchParams }: PageProps) {
if (typeof searchParams["platformId"] === "string")
platformIdList.push(searchParams["platformId"]);

const tab =
typeof searchParams["tab"] === "string" ? searchParams["tab"] : "trend";

return (
<>
<Suspense fallback={<ScreenLoader />}>
<HomeTemplate
<ArticleTemplate
languageStatus={languageStatus}
keyword={keyword}
platformIdList={platformIdList}
tab={tab}
tab={"summary"}
/>
</Suspense>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,21 @@ export const MobileHeader: FC<MobileHeaderProps> = ({

const pageName = useMemo(() => {
switch (pathname) {
case NAVIGATION_LISTS.DASHBOARD_TREND || NAVIGATION_LISTS.HOME:
case NAVIGATION_LISTS.DASHBOARD_TREND:
return "Trend";
case NAVIGATION_LISTS.DASHBOARD_SITE || NAVIGATION_LISTS.SITE:
case NAVIGATION_LISTS.HOME:
return "Trend";
case NAVIGATION_LISTS.DASHBOARD_SITE:
return "Site";
case NAVIGATION_LISTS.SITE:
return "Site";
case NAVIGATION_LISTS.DASHBOARD_COMPANY || NAVIGATION_LISTS.COMPANY:
case NAVIGATION_LISTS.DASHBOARD_COMPANY:
return "Company";
case NAVIGATION_LISTS.DASHBOARD_SUMMARY || NAVIGATION_LISTS.SUMMARY:
case NAVIGATION_LISTS.COMPANY:
return "Company";
case NAVIGATION_LISTS.DASHBOARD_SUMMARY:
return "Summary";
case NAVIGATION_LISTS.SUMMARY:
return "Summary";
case NAVIGATION_LISTS.BOOKMARK:
return "Bookmark";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ArticleCardWrapper } from "./ArticleCardWrapper";
import { FetchArticlesAPIResponse } from "../actions/article";

type Props = {
user: User | undefined;
user?: User;
initialArticles: Array<ArticleType>;
favoriteArticleFolders: Array<FavoriteArticleFolderType>;
languageStatus: LanguageStatus;
Expand Down
122 changes: 122 additions & 0 deletions web/client/src/features/articles/components/ArticleTemplate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import Image from "next/image";
import { FC } from "react";

import { fetchArticlesAPI } from "@/features/articles/actions/article";
import { ArticleList } from "@/features/articles/components/ArticleList";
import { fetchFavoriteArticleFoldersAPI } from "@/features/favoriteArticleFolders/actions/favoriteArticleFolders";
import { SelectArticlePageTab } from "@/features/home/components/SelectArticlePageTab";
import { ArticleKeyWordSearchDialog } from "@/features/search/components/articles/Dialog";

import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";

import { LanguageStatus } from "@/types/language";

import { ENGLISH_IMAGE, JAPANESE_IMAGE } from "@/constant/image";

type ArticleTemplateProps = {
languageStatus: LanguageStatus;
keyword?: string;
platformIdList: Array<string>;
tab: "site" | "company" | "summary";
};

const TAB_LIST = {
ENGLISH: "english",
JAPANESE: "japanese",
};

export const ArticleTemplate: FC<ArticleTemplateProps> = async ({
languageStatus,
keyword,
platformIdList,
tab,
}) => {
const enArticleRes = await fetchArticlesAPI({
languageStatus: "2",
keyword,
platformIdList,
tab,
});
const jpArticleRes = await fetchArticlesAPI({
languageStatus: "1",
keyword,
platformIdList,
tab,
});

const resFavoriteArticleFolders = await fetchFavoriteArticleFoldersAPI({});

return (
<div>
<div className="fixed z-10 w-[90%] items-end justify-end bg-card md:flex md:w-[70%] md:justify-between md:px-4">
<h1 className="my-4 hidden text-2xl font-bold md:block">Trend</h1>
<div className="h-2 w-full md:hidden" />
<div className="h-16 w-full md:hidden">
<SelectArticlePageTab />
</div>
</div>
<div className=" h-16 " />

<Tabs defaultValue={convertTab(languageStatus)}>
<TabsList className="fixed z-10 mt-[-4px] w-[90%] pt-[4px] md:mt-[-10px] md:w-[70%] md:py-[10px]">
<TabsTrigger className="w-1/2" value={TAB_LIST.ENGLISH}>
<Image
className="inline-block"
src={ENGLISH_IMAGE}
alt={"EN"}
width={20}
height={20}
/>
<span className="ml-2 inline-block">En</span>
</TabsTrigger>
<TabsTrigger className="w-1/2" value={TAB_LIST.JAPANESE}>
<Image
className="inline-block"
src={JAPANESE_IMAGE}
alt={"JP"}
width={20}
height={20}
/>
<span className="ml-2 inline-block">Jp</span>
</TabsTrigger>
</TabsList>

<div className="h-[40px]" />
<TabsContent value={TAB_LIST.ENGLISH}>
<ArticleList
initialArticles={enArticleRes.data.articles}
favoriteArticleFolders={
resFavoriteArticleFolders.data.favoriteArticleFolders
}
languageStatus={2}
keyword={keyword}
platformIdList={platformIdList}
tab={"trend"}
fetchArticles={fetchArticlesAPI}
/>
</TabsContent>
<TabsContent value={TAB_LIST.JAPANESE}>
<ArticleList
initialArticles={jpArticleRes.data.articles}
favoriteArticleFolders={
resFavoriteArticleFolders.data.favoriteArticleFolders
}
languageStatus={1}
keyword={keyword}
platformIdList={platformIdList}
tab={"trend"}
fetchArticles={fetchArticlesAPI}
/>
</TabsContent>
</Tabs>

<div className="fixed bottom-20 right-4 z-50 md:hidden">
<ArticleKeyWordSearchDialog />
</div>
</div>
);
};

const convertTab = (languageStatus: LanguageStatus) => {
return languageStatus === 1 ? TAB_LIST.JAPANESE : TAB_LIST.ENGLISH;
};
20 changes: 16 additions & 4 deletions web/client/src/features/home/components/SelectArticlePageTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,30 @@ export const SelectArticlePageTab: FC<SelectArticlePageTabProps> = ({
const router = useRouter();
const pathname = usePathname();

console.log("🔥");
console.log(pathname);

const defaultTabValue = useMemo(() => {
switch (pathname) {
case NAVIGATION_LISTS.DASHBOARD_TREND || NAVIGATION_LISTS.HOME:
case NAVIGATION_LISTS.DASHBOARD_TREND:
return "0";
case NAVIGATION_LISTS.HOME:
return "0";
case NAVIGATION_LISTS.DASHBOARD_SITE || NAVIGATION_LISTS.SITE:
case NAVIGATION_LISTS.DASHBOARD_SITE:
return "1";
case NAVIGATION_LISTS.SITE:
return "1";
case NAVIGATION_LISTS.DASHBOARD_COMPANY || NAVIGATION_LISTS.COMPANY:
case NAVIGATION_LISTS.DASHBOARD_COMPANY:
return "2";
case NAVIGATION_LISTS.DASHBOARD_SUMMARY || NAVIGATION_LISTS.SUMMARY:
case NAVIGATION_LISTS.COMPANY:
return "2";
case NAVIGATION_LISTS.DASHBOARD_SUMMARY:
return "3";
case NAVIGATION_LISTS.SUMMARY:
return "3";
}
}, [pathname]);
console.log(defaultTabValue);

const onMovePage = useCallback(
(value: string) => {
Expand Down

0 comments on commit c6ef8ec

Please sign in to comment.