Skip to content

Commit

Permalink
Merge branch 'release/0.1.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
YukiOnishi1129 committed Jun 8, 2024
2 parents 286af13 + 8ee28f3 commit d16332a
Show file tree
Hide file tree
Showing 31 changed files with 1,502 additions and 133 deletions.
2 changes: 2 additions & 0 deletions web/admin/src/app/api/feeds/count/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export async function GET(req: NextRequest) {
const platformId = searchParams.get("platformId") || undefined;
const categoryId = searchParams.get("categoryId") || undefined;
const trendPlatformType = searchParams.get("trendPlatformType") || undefined;
const status = searchParams.get("status") || undefined;

const count = await getFeedsCount({
keyword: keyword,
Expand All @@ -22,6 +23,7 @@ export async function GET(req: NextRequest) {
platformId: platformId,
categoryId: categoryId,
trendPlatformType: trendPlatformType,
status: status,
});
return NextResponse.json(
{
Expand Down
2 changes: 2 additions & 0 deletions web/admin/src/app/api/feeds/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export async function GET(req: NextRequest) {
const platformId = searchParams.get("platformId") || undefined;
const categoryId = searchParams.get("categoryId") || undefined;
const trendPlatformType = searchParams.get("trendPlatformType") || undefined;
const status = searchParams.get("status") || undefined;

const feeds = await getFeeds({
keyword: keyword,
Expand All @@ -20,6 +21,7 @@ export async function GET(req: NextRequest) {
platformId: platformId,
categoryId: categoryId,
trendPlatformType: trendPlatformType,
status: status,
});
return NextResponse.json(
{
Expand Down
6 changes: 6 additions & 0 deletions web/admin/src/app/feed/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export default function FeedPage({ searchParams }: PageProps) {
? searchParams["trendPlatformType"]
: undefined;

const status =
typeof searchParams["status"] === "string"
? searchParams["status"]
: undefined;

return (
<FeedTemplate
offset={offset}
Expand All @@ -47,6 +52,7 @@ export default function FeedPage({ searchParams }: PageProps) {
platformId={platformId}
categoryId={categoryId}
trendPlatformType={trendPlatformType}
status={status}
/>
);
}
47 changes: 47 additions & 0 deletions web/admin/src/components/ui/UpdateStatusForm/UpdateStatusForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"use client";

import { FaRunning, FaRegStopCircle } from "react-icons/fa";

import { Button } from "@/components/ui/button";

type UpdateStatusFormProps = {
isDisabledActive: boolean;
isDisabledStop: boolean;
handleUpdateStatusToActive: () => void;
handleUpdateStatusToStop: () => void;
};

export const UpdateStatusForm: React.FC<UpdateStatusFormProps> = ({
isDisabledActive,
isDisabledStop,
handleUpdateStatusToActive,
handleUpdateStatusToStop,
}) => {
return (
<div className="flex items-center justify-between">
{/* active */}
<div className="mr-2">
<Button
disabled={isDisabledActive}
variant="ghost"
onClick={handleUpdateStatusToActive}
>
<FaRunning className="mr-1" />
<span className="text-xs">ACTIVE</span>
</Button>
</div>

{/* stop */}
<div>
<Button
disabled={isDisabledStop}
variant="ghost"
onClick={handleUpdateStatusToStop}
>
<FaRegStopCircle className="mr-1" />
<span className="text-xs">STOP</span>
</Button>
</div>
</div>
);
};
1 change: 1 addition & 0 deletions web/admin/src/components/ui/UpdateStatusForm/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./UpdateStatusForm";
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FadeLoader } from "react-spinners";

export const Loader = () => {
export const FadeLoaderComponent = () => {
return <FadeLoader color="#36d7b7" className="inline-block" />;
};
29 changes: 29 additions & 0 deletions web/admin/src/components/ui/loader/SyncLoaderComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { FC } from "react";
import { SyncLoader } from "react-spinners";

type SyncLoaderComponentProps = {
loading?: boolean;
color?: string;
speedMultiplier?: number;
size?: number;
margin?: number;
};

export const SyncLoaderComponent: FC<SyncLoaderComponentProps> = ({
loading = true,
color = "#36d7b7",
speedMultiplier = 1,
size = 15,
margin = 2,
}: SyncLoaderComponentProps) => {
return (
<SyncLoader
loading={loading}
color={color}
speedMultiplier={speedMultiplier}
size={size}
margin={margin}
className="inline-block"
/>
);
};
2 changes: 2 additions & 0 deletions web/admin/src/components/ui/loader/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./FadeLoaderComponent";
export * from "./SyncLoaderComponent";
5 changes: 5 additions & 0 deletions web/admin/src/constants/status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const STATUS_LIST = [
{ value: 0, label: "all" },
{ value: 1, label: "active" },
{ value: 2, label: "stop" },
];
10 changes: 10 additions & 0 deletions web/admin/src/features/feeds/actions/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type FetchFeedsAPIRequest = {
platformId?: string;
categoryId?: string;
trendPlatformType?: string;
operationStatus?: string;
};

export const fetchFeedsAPI = async ({
Expand All @@ -31,6 +32,7 @@ export const fetchFeedsAPI = async ({
platformId,
categoryId,
trendPlatformType,
operationStatus,
}: FetchFeedsAPIRequest): Promise<FetchFeedsAPIResponse> => {
let url = `${process.env.WEB_DOMAIN}/api/feeds/?offset=${offset}`;
if (keyword) {
Expand All @@ -57,6 +59,9 @@ export const fetchFeedsAPI = async ({
if (trendPlatformType) {
url += `&trendPlatformType=${trendPlatformType}`;
}
if (operationStatus) {
url += `&status=${operationStatus}`;
}

const res = await getFetch({
url: url,
Expand All @@ -83,6 +88,7 @@ type FetchFeedsCountAPIRequest = {
platformId?: string;
categoryId?: string;
trendPlatformType?: string;
operationStatus?: string;
};

export const fetchFeedsCountAPI = async ({
Expand All @@ -94,6 +100,7 @@ export const fetchFeedsCountAPI = async ({
platformId,
categoryId,
trendPlatformType,
operationStatus,
}: FetchFeedsCountAPIRequest): Promise<FetchCountAPIResponse> => {
let url = `${process.env.WEB_DOMAIN}/api/feeds/count/?dummy=dummy`;
if (keyword) {
Expand All @@ -120,6 +127,9 @@ export const fetchFeedsCountAPI = async ({
if (trendPlatformType) {
url += `&trendPlatformType=${trendPlatformType}`;
}
if (operationStatus) {
url += `&status=${operationStatus}`;
}

const res = await getFetch({
url: url,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
"use client";

import { useState, useCallback } from "react";
import { useState, useCallback, FC } from "react";
import { FiPlus } from "react-icons/fi";

import { Button } from "@/components/ui/button";
import { Dialog, DialogTrigger } from "@/components/ui/dialog";

import { CreateFeedDialogContent } from "./CreateFeedDialogContent";

export const CreateFeedDialog = () => {
type CreateFeedDialogProps = {
offset?: number;
keyword?: string;
language?: string;
platformId?: string;
categoryId?: string;
platformSiteType?: string;
trendPlatformType?: string;
status?: string;
};
export const CreateFeedDialog: FC<CreateFeedDialogProps> = ({
offset,
keyword,
language,
platformId,
categoryId,
platformSiteType,
trendPlatformType,
status,
}) => {
const [openDialog, setOpenDialog] = useState(false);
const handleDialogOpen = useCallback(() => setOpenDialog(true), []);
const handleDialogClose = useCallback(() => setOpenDialog(false), []);
Expand All @@ -21,7 +40,17 @@ export const CreateFeedDialog = () => {
</Button>
</DialogTrigger>
{openDialog && (
<CreateFeedDialogContent handleDialogClose={handleDialogClose} />
<CreateFeedDialogContent
offset={offset}
keyword={keyword}
language={language}
platformId={platformId}
categoryId={categoryId}
platformSiteType={platformSiteType}
trendPlatformType={trendPlatformType}
status={status}
handleDialogClose={handleDialogClose}
/>
)}
</Dialog>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { zodResolver } from "@hookform/resolvers/zod";
import { ReloadIcon } from "@radix-ui/react-icons";
import { useRouter } from "next/navigation";
import { FC, useCallback, useState, useTransition } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";
Expand All @@ -25,7 +24,7 @@ import {
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { Loader } from "@/components/ui/loader";
import { FadeLoaderComponent } from "@/components/ui/loader";
import {
Select,
SelectContent,
Expand All @@ -36,13 +35,13 @@ import {
import { SheetClose } from "@/components/ui/sheet";
import { Textarea } from "@/components/ui/textarea";

import { useServerRevalidatePage } from "@/hooks/useServerRevalidatePage";
import { useStatusToast } from "@/hooks/useStatusToast";

import { CategoryType } from "@/types/category";
import { PlatformType } from "@/types/platform";

import { fetchFeedsCountAPI } from "../../actions/feed";
import { useRedirectPage } from "../../hooks/useRedirectPage";
import { createFeed } from "../../repository/feed";
import { SelectCategoryDialog } from "../SelectCategoryDialog";
import { SelectPlatformDialog } from "../SelectPlatformDialog";
Expand Down Expand Up @@ -89,14 +88,29 @@ const FormSchema = z.object({
});

type CreateFeedDialogContentProps = {
offset?: number;
keyword?: string;
language?: string;
platformId?: string;
categoryId?: string;
platformSiteType?: string;
trendPlatformType?: string;
status?: string;
handleDialogClose: () => void;
};

export const CreateFeedDialogContent: FC<CreateFeedDialogContentProps> = ({
offset,
keyword,
language,
platformId,
categoryId,
platformSiteType,
trendPlatformType,
status,
handleDialogClose,
}) => {
const router = useRouter();
const { revalidatePage } = useServerRevalidatePage();
const { redirectPage } = useRedirectPage();
const { successToast, failToast } = useStatusToast();
const form = useForm<z.infer<typeof FormSchema>>({
resolver: zodResolver(FormSchema),
Expand Down Expand Up @@ -196,11 +210,34 @@ export const CreateFeedDialogContent: FC<CreateFeedDialogContentProps> = ({
});

// 3. revalidate
await revalidatePage();
router.replace(`/feed`);
await redirectPage({
offset: offset,
targetKeyword: keyword,
targetLanguage: language,
targetPlatformSiteType: platformSiteType,
targetPlatformId: platformId,
targetCategoryId: categoryId,
targetTrendPlatformType: trendPlatformType,
targetStatus: status,
});
handleDialogClose();
});
},
[revalidatePage, router, successToast, failToast, isCheckExitSameRssUrl]
[
offset,
keyword,
language,
platformSiteType,
platformId,
categoryId,
trendPlatformType,
status,
redirectPage,
successToast,
failToast,
isCheckExitSameRssUrl,
handleDialogClose,
]
);

return (
Expand Down Expand Up @@ -267,7 +304,7 @@ export const CreateFeedDialogContent: FC<CreateFeedDialogContentProps> = ({
</FormLabel>
<div className="flex h-6 w-full items-center">
{isPlatformPending ? (
<Loader />
<FadeLoaderComponent />
) : (
<div className="flex w-full items-center justify-between">
<div className="flex ">
Expand Down Expand Up @@ -305,7 +342,7 @@ export const CreateFeedDialogContent: FC<CreateFeedDialogContentProps> = ({
<span className="text-red-700"> *</span>
</FormLabel>
{isCategoryPending ? (
<Loader />
<FadeLoaderComponent />
) : (
<div className="flex w-full items-center justify-between">
<div className="flex">
Expand Down
Loading

0 comments on commit d16332a

Please sign in to comment.