From 43bd34485919edef94ad0d643c66066556b3e579 Mon Sep 17 00:00:00 2001 From: kawamataryo Date: Mon, 13 Jan 2025 12:06:15 +0900 Subject: [PATCH] refactor: fix directory structure --- .storybook/main.ts | 20 +++++++++++-------- src/{lib => }/components/ActionButton.tsx | 0 .../components/AlertError.stories.tsx | 0 src/{lib => }/components/AlertError.tsx | 0 .../components/AlertSuccess.stories.tsx | 0 src/{lib => }/components/AlertSuccess.tsx | 0 .../components/AsyncButton.stories.tsx | 0 src/{lib => }/components/AsyncButton.tsx | 0 .../components/ConfirmDialog.stories.tsx | 0 src/{lib => }/components/ConfirmDialog.tsx | 0 .../DetectedUserListItem.stories.tsx | 2 +- .../components/DetectedUserListItem.tsx | 2 +- .../components/DetectedUserSource.tsx | 0 src/{lib => }/components/DonationCard.tsx | 0 .../components/Icons/AvatarFallbackSvg.tsx | 0 .../components/Icons/BlueskyIconSvg.tsx | 0 .../components/LoadingCards.stories.tsx | 0 src/{lib => }/components/LoadingCards.tsx | 0 src/{lib => }/components/LoginForm.tsx | 0 src/{lib => }/components/Modal.stories.tsx | 0 src/{lib => }/components/Modal.tsx | 0 src/components/ReSearchModal.tsx | 4 ++-- src/{lib => }/components/Sidebar.stories.tsx | 2 +- src/{lib => }/components/Sidebar.tsx | 6 +++--- .../components/SocialLinks.stories.tsx | 0 src/{lib => }/components/SocialLinks.tsx | 0 src/{lib => }/components/UserCard.stories.tsx | 6 +++++- src/{lib => }/components/UserCard.tsx | 0 src/{lib => }/components/UserCardSkeleton.tsx | 0 .../components/UserCardSkelton.stories.tsx | 0 .../UserCardWithoutActionButton.tsx | 0 src/{lib => }/components/UserInfo.tsx | 0 src/{lib => }/components/UserProfile.tsx | 0 src/contents/App.tsx | 8 ++++---- src/{lib => }/hooks/useAuth.ts | 0 src/{lib => }/hooks/useBskyUserManager.ts | 0 src/{lib => }/hooks/useErrorMessage.ts | 0 src/{lib => }/hooks/useRetrieveBskyUsers.ts | 6 +++--- src/{lib => }/hooks/useSearch.ts | 0 src/options.tsx | 11 +++++----- src/popup.tsx | 6 ++---- src/{lib => }/services/instagramService.ts | 0 src/{lib => }/services/threadsService.ts | 0 src/{lib => }/services/xService.ts | 0 44 files changed, 39 insertions(+), 34 deletions(-) rename src/{lib => }/components/ActionButton.tsx (100%) rename src/{lib => }/components/AlertError.stories.tsx (100%) rename src/{lib => }/components/AlertError.tsx (100%) rename src/{lib => }/components/AlertSuccess.stories.tsx (100%) rename src/{lib => }/components/AlertSuccess.tsx (100%) rename src/{lib => }/components/AsyncButton.stories.tsx (100%) rename src/{lib => }/components/AsyncButton.tsx (100%) rename src/{lib => }/components/ConfirmDialog.stories.tsx (100%) rename src/{lib => }/components/ConfirmDialog.tsx (100%) rename src/{lib => }/components/DetectedUserListItem.stories.tsx (97%) rename src/{lib => }/components/DetectedUserListItem.tsx (98%) rename src/{lib => }/components/DetectedUserSource.tsx (100%) rename src/{lib => }/components/DonationCard.tsx (100%) rename src/{lib => }/components/Icons/AvatarFallbackSvg.tsx (100%) rename src/{lib => }/components/Icons/BlueskyIconSvg.tsx (100%) rename src/{lib => }/components/LoadingCards.stories.tsx (100%) rename src/{lib => }/components/LoadingCards.tsx (100%) rename src/{lib => }/components/LoginForm.tsx (100%) rename src/{lib => }/components/Modal.stories.tsx (100%) rename src/{lib => }/components/Modal.tsx (100%) rename src/{lib => }/components/Sidebar.stories.tsx (96%) rename src/{lib => }/components/Sidebar.tsx (98%) rename src/{lib => }/components/SocialLinks.stories.tsx (100%) rename src/{lib => }/components/SocialLinks.tsx (100%) rename src/{lib => }/components/UserCard.stories.tsx (90%) rename src/{lib => }/components/UserCard.tsx (100%) rename src/{lib => }/components/UserCardSkeleton.tsx (100%) rename src/{lib => }/components/UserCardSkelton.stories.tsx (100%) rename src/{lib => }/components/UserCardWithoutActionButton.tsx (100%) rename src/{lib => }/components/UserInfo.tsx (100%) rename src/{lib => }/components/UserProfile.tsx (100%) rename src/{lib => }/hooks/useAuth.ts (100%) rename src/{lib => }/hooks/useBskyUserManager.ts (100%) rename src/{lib => }/hooks/useErrorMessage.ts (100%) rename src/{lib => }/hooks/useRetrieveBskyUsers.ts (97%) rename src/{lib => }/hooks/useSearch.ts (100%) rename src/{lib => }/services/instagramService.ts (100%) rename src/{lib => }/services/threadsService.ts (100%) rename src/{lib => }/services/xService.ts (100%) diff --git a/.storybook/main.ts b/.storybook/main.ts index a3a4c83..0c36904 100644 --- a/.storybook/main.ts +++ b/.storybook/main.ts @@ -1,4 +1,6 @@ import type { StorybookConfig } from "@storybook/react-vite"; +import { mergeConfig } from "vite"; +import path from "node:path"; const config: StorybookConfig = { stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"], @@ -13,15 +15,17 @@ const config: StorybookConfig = { name: "@storybook/react-vite", options: {}, }, - viteFinal: (config) => { - config.define = { - ...config.define, - "process.env": process.env, - esbuild: { - jsx: "automatic", + viteFinal: async (config) => { + return mergeConfig(config, { + resolve: { + alias: { + "~": path.resolve(__dirname, "../src/"), + }, }, - }; - return config; + define: { + "process.env": {} + }, + }); }, typescript: { reactDocgen: "react-docgen-typescript", diff --git a/src/lib/components/ActionButton.tsx b/src/components/ActionButton.tsx similarity index 100% rename from src/lib/components/ActionButton.tsx rename to src/components/ActionButton.tsx diff --git a/src/lib/components/AlertError.stories.tsx b/src/components/AlertError.stories.tsx similarity index 100% rename from src/lib/components/AlertError.stories.tsx rename to src/components/AlertError.stories.tsx diff --git a/src/lib/components/AlertError.tsx b/src/components/AlertError.tsx similarity index 100% rename from src/lib/components/AlertError.tsx rename to src/components/AlertError.tsx diff --git a/src/lib/components/AlertSuccess.stories.tsx b/src/components/AlertSuccess.stories.tsx similarity index 100% rename from src/lib/components/AlertSuccess.stories.tsx rename to src/components/AlertSuccess.stories.tsx diff --git a/src/lib/components/AlertSuccess.tsx b/src/components/AlertSuccess.tsx similarity index 100% rename from src/lib/components/AlertSuccess.tsx rename to src/components/AlertSuccess.tsx diff --git a/src/lib/components/AsyncButton.stories.tsx b/src/components/AsyncButton.stories.tsx similarity index 100% rename from src/lib/components/AsyncButton.stories.tsx rename to src/components/AsyncButton.stories.tsx diff --git a/src/lib/components/AsyncButton.tsx b/src/components/AsyncButton.tsx similarity index 100% rename from src/lib/components/AsyncButton.tsx rename to src/components/AsyncButton.tsx diff --git a/src/lib/components/ConfirmDialog.stories.tsx b/src/components/ConfirmDialog.stories.tsx similarity index 100% rename from src/lib/components/ConfirmDialog.stories.tsx rename to src/components/ConfirmDialog.stories.tsx diff --git a/src/lib/components/ConfirmDialog.tsx b/src/components/ConfirmDialog.tsx similarity index 100% rename from src/lib/components/ConfirmDialog.tsx rename to src/components/ConfirmDialog.tsx diff --git a/src/lib/components/DetectedUserListItem.stories.tsx b/src/components/DetectedUserListItem.stories.tsx similarity index 97% rename from src/lib/components/DetectedUserListItem.stories.tsx rename to src/components/DetectedUserListItem.stories.tsx index b951c5b..37dae58 100644 --- a/src/lib/components/DetectedUserListItem.stories.tsx +++ b/src/components/DetectedUserListItem.stories.tsx @@ -1,6 +1,6 @@ import type { Meta, StoryObj } from "@storybook/react"; -import { ACTION_MODE, BSKY_USER_MATCH_TYPE } from "../constants"; +import { ACTION_MODE, BSKY_USER_MATCH_TYPE } from "~lib/constants"; import DetectedUserListItem, { type Props } from "./DetectedUserListItem"; const meta: Meta = { diff --git a/src/lib/components/DetectedUserListItem.tsx b/src/components/DetectedUserListItem.tsx similarity index 98% rename from src/lib/components/DetectedUserListItem.tsx rename to src/components/DetectedUserListItem.tsx index 4523fd7..c225334 100644 --- a/src/lib/components/DetectedUserListItem.tsx +++ b/src/components/DetectedUserListItem.tsx @@ -1,8 +1,8 @@ import type { ProfileView } from "@atproto/api/dist/client/types/app/bsky/actor/defs"; import React from "react"; import { match } from "ts-pattern"; +import { ACTION_MODE, MATCH_TYPE_LABEL_AND_COLOR } from "~lib/constants"; import type { BskyUser } from "~types"; -import { ACTION_MODE, MATCH_TYPE_LABEL_AND_COLOR } from "../constants"; import DetectedUserSource from "./DetectedUserSource"; import UserCard from "./UserCard"; export type Props = { diff --git a/src/lib/components/DetectedUserSource.tsx b/src/components/DetectedUserSource.tsx similarity index 100% rename from src/lib/components/DetectedUserSource.tsx rename to src/components/DetectedUserSource.tsx diff --git a/src/lib/components/DonationCard.tsx b/src/components/DonationCard.tsx similarity index 100% rename from src/lib/components/DonationCard.tsx rename to src/components/DonationCard.tsx diff --git a/src/lib/components/Icons/AvatarFallbackSvg.tsx b/src/components/Icons/AvatarFallbackSvg.tsx similarity index 100% rename from src/lib/components/Icons/AvatarFallbackSvg.tsx rename to src/components/Icons/AvatarFallbackSvg.tsx diff --git a/src/lib/components/Icons/BlueskyIconSvg.tsx b/src/components/Icons/BlueskyIconSvg.tsx similarity index 100% rename from src/lib/components/Icons/BlueskyIconSvg.tsx rename to src/components/Icons/BlueskyIconSvg.tsx diff --git a/src/lib/components/LoadingCards.stories.tsx b/src/components/LoadingCards.stories.tsx similarity index 100% rename from src/lib/components/LoadingCards.stories.tsx rename to src/components/LoadingCards.stories.tsx diff --git a/src/lib/components/LoadingCards.tsx b/src/components/LoadingCards.tsx similarity index 100% rename from src/lib/components/LoadingCards.tsx rename to src/components/LoadingCards.tsx diff --git a/src/lib/components/LoginForm.tsx b/src/components/LoginForm.tsx similarity index 100% rename from src/lib/components/LoginForm.tsx rename to src/components/LoginForm.tsx diff --git a/src/lib/components/Modal.stories.tsx b/src/components/Modal.stories.tsx similarity index 100% rename from src/lib/components/Modal.stories.tsx rename to src/components/Modal.stories.tsx diff --git a/src/lib/components/Modal.tsx b/src/components/Modal.tsx similarity index 100% rename from src/lib/components/Modal.tsx rename to src/components/Modal.tsx diff --git a/src/components/ReSearchModal.tsx b/src/components/ReSearchModal.tsx index 3491185..1d3fd8e 100644 --- a/src/components/ReSearchModal.tsx +++ b/src/components/ReSearchModal.tsx @@ -1,6 +1,6 @@ import type { ProfileView } from "@atproto/api/dist/client/types/app/bsky/actor/defs"; -import Modal from "~lib/components/Modal"; -import UserCardWithoutActionButton from "~lib/components/UserCardWithoutActionButton"; +import Modal from "components/Modal"; +import UserCardWithoutActionButton from "components/UserCardWithoutActionButton"; interface ReSearchModalProps { open: boolean; diff --git a/src/lib/components/Sidebar.stories.tsx b/src/components/Sidebar.stories.tsx similarity index 96% rename from src/lib/components/Sidebar.stories.tsx rename to src/components/Sidebar.stories.tsx index 39582c6..1158199 100644 --- a/src/lib/components/Sidebar.stories.tsx +++ b/src/components/Sidebar.stories.tsx @@ -1,5 +1,5 @@ import type { Meta, StoryObj } from "@storybook/react"; -import { ACTION_MODE, BSKY_USER_MATCH_TYPE } from "../constants"; +import { ACTION_MODE, BSKY_USER_MATCH_TYPE } from "~lib/constants"; import Sidebar from "./Sidebar"; const meta = { diff --git a/src/lib/components/Sidebar.tsx b/src/components/Sidebar.tsx similarity index 98% rename from src/lib/components/Sidebar.tsx rename to src/components/Sidebar.tsx index 6cdc412..aa794cf 100644 --- a/src/lib/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -1,12 +1,12 @@ import React from "react"; import { match } from "ts-pattern"; -import { getMessageWithLink } from "~lib/utils"; -import type { MatchType, MatchTypeFilterValue } from "../../types"; import { ACTION_MODE, BSKY_USER_MATCH_TYPE, MATCH_TYPE_LABEL_AND_COLOR, -} from "../constants"; +} from "~lib/constants"; +import { getMessageWithLink } from "~lib/utils"; +import type { MatchType, MatchTypeFilterValue } from "~types"; import AsyncButton from "./AsyncButton"; import SocialLinks from "./SocialLinks"; diff --git a/src/lib/components/SocialLinks.stories.tsx b/src/components/SocialLinks.stories.tsx similarity index 100% rename from src/lib/components/SocialLinks.stories.tsx rename to src/components/SocialLinks.stories.tsx diff --git a/src/lib/components/SocialLinks.tsx b/src/components/SocialLinks.tsx similarity index 100% rename from src/lib/components/SocialLinks.tsx rename to src/components/SocialLinks.tsx diff --git a/src/lib/components/UserCard.stories.tsx b/src/components/UserCard.stories.tsx similarity index 90% rename from src/lib/components/UserCard.stories.tsx rename to src/components/UserCard.stories.tsx index 70f3366..d4ab5c9 100644 --- a/src/lib/components/UserCard.stories.tsx +++ b/src/components/UserCard.stories.tsx @@ -1,6 +1,6 @@ import type { Meta, StoryObj } from "@storybook/react"; -import { BSKY_USER_MATCH_TYPE } from "../constants"; +import { BSKY_USER_MATCH_TYPE } from "~lib/constants"; import UserCard, { type UserCardProps } from "./UserCard"; const meta: Meta = { @@ -46,6 +46,8 @@ const CardTemplate = { handleActionButtonClick={() => {}} setIsBtnHovered={() => {}} setIsJustClicked={() => {}} + handleReSearchClick={() => {}} + handleDeleteClick={() => {}} /> ), }; @@ -63,6 +65,8 @@ const CardsTemplate: Story = { handleActionButtonClick={() => {}} setIsBtnHovered={() => {}} setIsJustClicked={() => {}} + handleReSearchClick={() => {}} + handleDeleteClick={() => {}} /> ))} diff --git a/src/lib/components/UserCard.tsx b/src/components/UserCard.tsx similarity index 100% rename from src/lib/components/UserCard.tsx rename to src/components/UserCard.tsx diff --git a/src/lib/components/UserCardSkeleton.tsx b/src/components/UserCardSkeleton.tsx similarity index 100% rename from src/lib/components/UserCardSkeleton.tsx rename to src/components/UserCardSkeleton.tsx diff --git a/src/lib/components/UserCardSkelton.stories.tsx b/src/components/UserCardSkelton.stories.tsx similarity index 100% rename from src/lib/components/UserCardSkelton.stories.tsx rename to src/components/UserCardSkelton.stories.tsx diff --git a/src/lib/components/UserCardWithoutActionButton.tsx b/src/components/UserCardWithoutActionButton.tsx similarity index 100% rename from src/lib/components/UserCardWithoutActionButton.tsx rename to src/components/UserCardWithoutActionButton.tsx diff --git a/src/lib/components/UserInfo.tsx b/src/components/UserInfo.tsx similarity index 100% rename from src/lib/components/UserInfo.tsx rename to src/components/UserInfo.tsx diff --git a/src/lib/components/UserProfile.tsx b/src/components/UserProfile.tsx similarity index 100% rename from src/lib/components/UserProfile.tsx rename to src/components/UserProfile.tsx diff --git a/src/contents/App.tsx b/src/contents/App.tsx index 4b96ddd..99905a2 100644 --- a/src/contents/App.tsx +++ b/src/contents/App.tsx @@ -5,11 +5,11 @@ import { useStorage } from "@plasmohq/storage/hook"; import type { PlasmoCSConfig } from "plasmo"; import React from "react"; import { match } from "ts-pattern"; -import AlertError from "~lib/components/AlertError"; -import LoadingCards from "~lib/components/LoadingCards"; -import Modal from "~lib/components/Modal"; +import AlertError from "~components/AlertError"; +import LoadingCards from "~components/LoadingCards"; +import Modal from "~components/Modal"; +import { useRetrieveBskyUsers } from "~hooks/useRetrieveBskyUsers"; import { MESSAGE_NAMES, SERVICE_TYPE, STORAGE_KEYS } from "~lib/constants"; -import { useRetrieveBskyUsers } from "~lib/hooks/useRetrieveBskyUsers"; export const config: PlasmoCSConfig = { matches: [ diff --git a/src/lib/hooks/useAuth.ts b/src/hooks/useAuth.ts similarity index 100% rename from src/lib/hooks/useAuth.ts rename to src/hooks/useAuth.ts diff --git a/src/lib/hooks/useBskyUserManager.ts b/src/hooks/useBskyUserManager.ts similarity index 100% rename from src/lib/hooks/useBskyUserManager.ts rename to src/hooks/useBskyUserManager.ts diff --git a/src/lib/hooks/useErrorMessage.ts b/src/hooks/useErrorMessage.ts similarity index 100% rename from src/lib/hooks/useErrorMessage.ts rename to src/hooks/useErrorMessage.ts diff --git a/src/lib/hooks/useRetrieveBskyUsers.ts b/src/hooks/useRetrieveBskyUsers.ts similarity index 97% rename from src/lib/hooks/useRetrieveBskyUsers.ts rename to src/hooks/useRetrieveBskyUsers.ts index c759a0e..42b2bae 100644 --- a/src/lib/hooks/useRetrieveBskyUsers.ts +++ b/src/hooks/useRetrieveBskyUsers.ts @@ -7,10 +7,10 @@ import { BskyServiceWorkerClient } from "~lib/bskyServiceWorkerClient"; import { getChromeStorage } from "~lib/chromeHelper"; import { MESSAGE_NAMES, SERVICE_TYPE, STORAGE_KEYS } from "~lib/constants"; import { searchBskyUser } from "~lib/searchBskyUsers"; -import { InstagramService } from "~lib/services/instagramService"; -import { ThreadsService } from "~lib/services/threadsService"; -import { XService } from "~lib/services/xService"; import { wait } from "~lib/utils"; +import { InstagramService } from "~services/instagramService"; +import { ThreadsService } from "~services/threadsService"; +import { XService } from "~services/xService"; import type { BskyUser, CrawledUserInfo, diff --git a/src/lib/hooks/useSearch.ts b/src/hooks/useSearch.ts similarity index 100% rename from src/lib/hooks/useSearch.ts rename to src/hooks/useSearch.ts diff --git a/src/options.tsx b/src/options.tsx index a0a50da..c8be722 100644 --- a/src/options.tsx +++ b/src/options.tsx @@ -1,16 +1,15 @@ -import { useBskyUserManager } from "~lib/hooks/useBskyUserManager"; +import { useBskyUserManager } from "~hooks/useBskyUserManager"; import "./style.css"; import { ToastContainer, toast } from "react-toastify"; -import useConfirm from "~lib/components/ConfirmDialog"; -import Sidebar from "~lib/components/Sidebar"; +import useConfirm from "~components/ConfirmDialog"; +import Sidebar from "~components/Sidebar"; import "react-toastify/dist/ReactToastify.css"; import type { ProfileView } from "@atproto/api/dist/client/types/app/bsky/actor/defs"; import { useVirtualizer } from "@tanstack/react-virtual"; -import { AnimatePresence, motion } from "framer-motion"; import React from "react"; +import DetectedUserListItem from "~components/DetectedUserListItem"; +import DonationCard from "~components/DonationCard"; import ReSearchModal from "~components/ReSearchModal"; -import DetectedUserListItem from "~lib/components/DetectedUserListItem"; -import DonationCard from "~lib/components/DonationCard"; const Option = () => { const { diff --git a/src/popup.tsx b/src/popup.tsx index 85122c4..3cb557d 100644 --- a/src/popup.tsx +++ b/src/popup.tsx @@ -1,4 +1,3 @@ -import { useEffect } from "react"; import packageJson from "../package.json"; import "./style.css"; @@ -7,9 +6,8 @@ import { AuthForm } from "~components/popup/AuthForm"; import { ErrorMessage } from "~components/popup/ErrorMessage"; import { Header } from "~components/popup/Header"; import { SearchForm } from "~components/popup/SearchForm"; -import { MESSAGE_TYPE } from "~lib/constants"; -import { useAuth } from "~lib/hooks/useAuth"; -import { useSearch } from "~lib/hooks/useSearch"; +import { useAuth } from "~hooks/useAuth"; +import { useSearch } from "~hooks/useSearch"; function IndexPopup() { const { diff --git a/src/lib/services/instagramService.ts b/src/services/instagramService.ts similarity index 100% rename from src/lib/services/instagramService.ts rename to src/services/instagramService.ts diff --git a/src/lib/services/threadsService.ts b/src/services/threadsService.ts similarity index 100% rename from src/lib/services/threadsService.ts rename to src/services/threadsService.ts diff --git a/src/lib/services/xService.ts b/src/services/xService.ts similarity index 100% rename from src/lib/services/xService.ts rename to src/services/xService.ts