Skip to content
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

Closed
wants to merge 14 commits into from
Closed

Conversation

yi-luan
Copy link
Collaborator

@yi-luan yi-luan commented Sep 21, 2023

Description

  1. The GitHub Action CI of React has beeb implemented.
  2. Upload the related dependencies.

@yi-luan yi-luan requested a review from ping-yee September 22, 2023 01:17
@yi-luan yi-luan changed the title React-CI Commit React-CI commit and upload related dependencies Sep 22, 2023
@ping-yee ping-yee changed the title React-CI commit and upload related dependencies feat: react-CI commit and upload related dependencies. Sep 22, 2023
@ping-yee ping-yee changed the title feat: react-CI commit and upload related dependencies. feat: react-CI commit and upload the related dependencies. Sep 22, 2023
@ping-yee ping-yee requested a review from Dlutermade September 22, 2023 02:11
@Dlutermade
Copy link

因為 前端 的奇怪特性 沒有編譯

所以我們會先 做 lint check
然後 type check
再 unit test

最後才 build

@WeiYun0912
Copy link

可以考慮在專案中使用 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";

而這個 @ 映射到的路徑是你的 src,所以不管你以後的檔案有多 deep,就不用一直使用 ../ 回到上一層去抓你要的檔案,直接用 @ 來回到根(src) 就好了。


具體的設定你可以這樣嘗試看看

tsconfig.json

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    },
    ....
  },
  ....
}

vite.config.ts

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"),
    },
  },
})

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 } />

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 = {

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)`,
   ...
}

@yi-luan yi-luan closed this Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants