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

frontend login #87

Merged
merged 6 commits into from
Dec 6, 2023
Merged

frontend login #87

merged 6 commits into from
Dec 6, 2023

Conversation

snowmancc
Copy link
Collaborator

@snowmancc snowmancc commented Jul 23, 2023

resolves #74

image

@snowmancc snowmancc changed the title temp frontend login Jul 23, 2023
@timt1028 timt1028 added the front-end front end issue label Aug 8, 2023
@snowmancc snowmancc force-pushed the frondend_login_game branch 2 times, most recently from 483c9e1 to ca20fdb Compare August 14, 2023 07:32
@snowmancc snowmancc marked this pull request as ready for review August 14, 2023 07:34
Copy link
Collaborator

@Irisloverain Irisloverain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

關於圖片沒能立即更新,因為React 有批次更新State的機制來提升效能,所以在同一個函式內使用一個setStateA帶入另一個StateB的話,在setStateA中值StateB仍是這次函式執行更新前值

setPortraitIndex()中的portraitChangeCount還是執行setPortraitChangeCount(portraitChangeCount + 1)前的值
可以改成:
setPortraitChangeCount(prevCount => prevCount + 1);
setPortraitIndex(prevIndex => (prevIndex + 1) % portraits.length);

也許也還有其他作法!><

Copy link
Collaborator

@Irisloverain Irisloverain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我切版時忘記在更換圖片那邊加滑鼠變成按鈕><
可以加個css:
className='login_change' onClick={changeImage}

在_login.scss加入:
&_change{
cursor: pointer;
}

Copy link
Collaborator

@Irisloverain Irisloverain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有幾個地方div變成dev啦XD

@dawnglede
Copy link
Collaborator

dawnglede commented Aug 14, 2023

關於圖片沒能立即更新,因為React 有批次更新State的機制來提升效能,所以在同一個函式內使用一個setStateA帶入另一個StateB的話,在setStateA中值StateB仍是這次函式執行更新前值

setPortraitIndex()中的portraitChangeCount還是執行setPortraitChangeCount(portraitChangeCount + 1)前的值 可以改成: setPortraitChangeCount(prevCount => prevCount + 1); setPortraitIndex(prevIndex => (prevIndex + 1) % portraits.length);

也許也還有其他作法!><

setPortraitIndex(prevIndex => (prevIndex + 1) % portraits.length) => 這裡他是要用更新之後的portraitChangeCount去計算index,所以不是用portraitIndex本身的前值
這裡用我的做法的話,會另外宣告變數去計算,計算完後再更新到state裡面:

  const changeImage = () => {
    const newChangeCount = portraitChangeCount + 1
    const newIndex = newChangeCount % portraits.length
    setPortraitChangeCount(newChangeCount)
    setPortraitIndex(newIndex)
  }

或是用useRef去儲存portraitChangeCount的值,這樣每次拿到都會是新值:

  const portraitChangeCount = useRef(0)
  const [portraitIndex, setPortraitIndex] = useState(0)
  const changeImage = () => {
    portraitChangeCount.current++
    setPortraitIndex(portraitChangeCount.current % portraits.length)
  }

@snowmancc snowmancc force-pushed the frondend_login_game branch 2 times, most recently from 5f3fcd2 to bbe8455 Compare September 7, 2023 16:32
Copy link
Collaborator

@dawnglede dawnglede left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Irisloverain
Copy link
Collaborator

LGTM

Copy link
Collaborator

@Irisloverain Irisloverain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@snowmancc snowmancc merged commit cb6f74a into main Dec 6, 2023
1 check passed
@snowmancc snowmancc deleted the frondend_login_game branch December 6, 2023 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
front-end front end issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

【前端】登入遊戲畫面和功能
4 participants