-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: react-CI commit and upload the related dependencies. #8
Conversation
# Conflicts: # .github/workflows/react-ci.yaml
因為 前端 的奇怪特性 沒有編譯 所以我們會先 做 lint check 最後才 build |
可以考慮在專案中使用 alias import 的方式 以你的 page/game/map.tsx 來舉例 原本你的 import 長這樣 import Card from "../../components/items/card";
import { LineUpCardsState } from "../../states/lineUpCardStates";
import { useRecoilState } from "recoil";
import lineUpCardBack from "../../assets/images/backOfLineUpCard.jpg";
import functionalCardBack from "../../assets/images/backOfFunctionCard.jpg"; 使用 alias 後會變成以下 import Card from "@/components/items/card";
import { LineUpCardsState } from "@/states/lineUpCardStates";
import { useRecoilState } from "recoil";
import lineUpCardBack from "@/assets/images/backOfLineUpCard.jpg";
import functionalCardBack from "@/assets/images/backOfFunctionCard.jpg"; 而這個 具體的設定你可以這樣嘗試看看
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
},
....
},
....
}
import { defineConfig } from "vite"
import react from "@vitejs/plugin-react-swc"
import path from "path";
export default defineConfig({
plugins: [react()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
15 行 cardBackUrl 的條件式可以拉出來判斷
const [ lineUpCards ] = useRecoilState(LineUpCardsState);
const {CardInformation,cardKind} = lineUpCards;
const isLineUp = cardKind === "LineUp";
const cardBackUrl = isLineUp ? lineUpCardBack : functionalCardBack;
CardInformation.map((card) => (
<Card ... cardBackUrl={cardBackUrl} />
))
<div className="h-full w-full" style={{position:'relative'}}> | ||
{ | ||
lineUpCards.CardInformation.map((card) => ( | ||
<Card key={card.cardName} cardName={card.cardName} cardFrontUrl={card.cardUrl} canBeTurn={card.canBeTurn} cardState={card.cardState} cardCoordinate={card.cardCoordinate} cardBackUrl={(lineUpCards.cardKind == "LineUp") ? lineUpCardBack : functionalCardBack } /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
props 要是太多要傳遞的話 可以考慮用 spread syntax
例如:
<Card key={card.cardName} {...card} cardFrontUrl={card.cardUrl} cardBackUrl={cardBackUrl} />
- 優點:Component 程式碼看起來不會那麼長
- 缺點:要是想看你傳遞了哪些 props 到 Child Component 就還要 console 看一下,但你的 Child Component 有 type guard 應該還好。
|
||
const Card:React.FC<CardProps> = ( { cardFrontUrl, cardBackUrl, cardState, canBeTurn, cardCoordinate } ) => { | ||
|
||
const cardPositionStyle = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以先用解構的方式取出你的 X,Y 比較易讀
const { currentCoordinateX, currentCoordinateY } = cardCoordinate;
const cardPositionStyle = {
top:`calc(50% + ${currentCoordinateX}px)`,
left:`calc(50% + ${currentCoordinateY}px)`,
...
}
Description