Skip to content

Commit

Permalink
switch
Browse files Browse the repository at this point in the history
  • Loading branch information
YukiOnishi1129 committed Apr 18, 2024
1 parent 8c5833e commit 181164c
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 25 deletions.
37 changes: 37 additions & 0 deletions web/client/src/components/ui/switch/LanguageSwitch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"use client";

import { Loader } from "lucide-react";
import { FC } from "react";

import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch";

type LanguageSwitchProps = {
isEng: boolean;
isLoading: boolean;
label: string;
onCheckedChange: (checked: boolean) => void;
};

export const LanguageSwitch: FC<LanguageSwitchProps> = ({
isEng,
isLoading,
label,
onCheckedChange,
}: LanguageSwitchProps) => {
return (
<div className="flex items-center justify-end space-x-2">
{isLoading ? (
<Loader />
) : (
<Switch
id="airplane-mode"
checked={isEng}
onCheckedChange={onCheckedChange}
/>
)}

<Label htmlFor="airplane-mode">{label}</Label>
</div>
);
};
2 changes: 2 additions & 0 deletions web/client/src/components/ui/switch/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./switch";
export * from "./LanguageSwitch";
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { ArticleTabType } from "@/types/article";
import { LanguageStatus } from "@/types/language";

import { ArticleLanguageSwitch } from "./ArticleLanguageSwitch";
import { ArticleList } from "./ArticleList";
import { ArticleLanguageSwitch } from "./Switch";
import { fetchArticlesAPI } from "../actions/article";

type ArticleListTemplateProps = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
"use client";

import { Loader } from "lucide-react";
import { useRouter } from "next/navigation";
import { FC, useCallback, useState } from "react";

import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch";
import { LanguageSwitch } from "@/components/ui/switch";

import { ArticleTabType } from "@/types/article";
import { LanguageStatus } from "@/types/language";
Expand Down Expand Up @@ -42,14 +40,11 @@ export const ArticleLanguageSwitch: FC<ArticleLanguageSwitchProps> = ({
);

return (
<div className="flex items-center justify-end space-x-2">
{isLoading ? (
<Loader />
) : (
<Switch id="airplane-mode" checked={isEng} onCheckedChange={onChange} />
)}

<Label htmlFor="airplane-mode">{switchLabel}</Label>
</div>
<LanguageSwitch
isEng={isEng}
isLoading={isLoading}
label={switchLabel}
onCheckedChange={onChange}
/>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./ArticleLanguageSwitch";
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
"use client";

import { Loader } from "lucide-react";
import { useRouter } from "next/navigation";
import { FC, useCallback, useState } from "react";

import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch";
import { LanguageSwitch } from "@/components/ui/switch";

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

Expand Down Expand Up @@ -39,14 +37,11 @@ export const BookmarkLanguageSwitch: FC<BookmarkLanguageSwitchProps> = ({
);

return (
<div className="flex items-center justify-end space-x-2">
{isLoading ? (
<Loader />
) : (
<Switch id="airplane-mode" checked={isEng} onCheckedChange={onChange} />
)}

<Label htmlFor="airplane-mode">{switchLabel}</Label>
</div>
<LanguageSwitch
isEng={isEng}
isLoading={isLoading}
label={switchLabel}
onCheckedChange={onChange}
/>
);
};

0 comments on commit 181164c

Please sign in to comment.