Git Product home page Git Product logo

보영 - 사용자가 좋아요(별표)를 광클해서 어쩌다 파베에 하나의 사용자가 하나의 질문에 대해 Like 데이터를 1개 이상 생성했을 때 발생할 수 있는 문제 해결 about sos HOT 2 CLOSED

fimuxd avatar fimuxd commented on July 28, 2024
보영 - 사용자가 좋아요(별표)를 광클해서 어쩌다 파베에 하나의 사용자가 하나의 질문에 대해 Like 데이터를 1개 이상 생성했을 때 발생할 수 있는 문제 해결

from sos.

Comments (2)

fimuxd avatar fimuxd commented on July 28, 2024

DetailVC 부분에 하기 코드 추가해서 수정하였습니다.
해당질문에 해당유저가 좋아요한 카운트가 0일 때는 종전과 그대로 데이터가 추가됩니다.
이때 빠른속도로 클릭했을 때 데이터가 받아들이는 속도 차이에 의해서 똑같은 Like 데이터가 중복입력될 수 있습니다.

screen shot 2017-10-09 at 11 05 04 am

따라서, 삭제할 때 같은 데이터가 있다면 모두 지워져야, 유저시선에서는 좋아요를 취소했음에도 불구하고 별표가 바뀌지 않는 에러를 방지할 수 있습니다.

첨삭/수정한 코드는 다음과 같습니다.

// DetailVC상의 likeButtonAction 함수 내 Switch 문

switch filteredLikeData.count {
                case 0: // 바뀐 것 없이 같음
                    self.favoriteButtonOutlet.setImage(#imageLiteral(resourceName: "Star_on"), for: .normal)
                    self.navigationViewFavoriteButtonOutlet.setImage(#imageLiteral(resourceName: "Star_on"), for: .normal)
                    Database.database().reference().child(Constants.like).childByAutoId().setValue([Constants.like_QuestionId:realQuestionID,
                                                                                                    Constants.like_User_Id:Auth.auth().currentUser?.uid])
                default: // case 1을 지우고 default로 바로 넘어감
                    self.favoriteButtonOutlet.setImage(#imageLiteral(resourceName: "Like_off"), for: .normal)
                    self.navigationViewFavoriteButtonOutlet.setImage(#imageLiteral(resourceName: "Like_off"), for: .normal)

                    for i in 0..<filteredLikeData.count { //for-in 문으로 돌림
                    Database.database().reference().child(Constants.like).child(filteredLikeData[i].key).setValue(nil)
                    }
                }

이렇게 하면 한번만 취소해도 모든 중복된 좋아요가 지워지게 됩니다.
screen shot 2017-10-09 at 11 08 28 am

from sos.

blackturtle2 avatar blackturtle2 commented on July 28, 2024

오오. 좋은(?) 버그네요. 굳굳입니다.

한가지 + 하자면, 보통 이런 버그 혹은 고도화에서는 통신 단에서 해결하지 않고, UI 단에서 해결하는 데요.
이 같은 경우에는, 좋아요 버튼을 한번 눌렀을 경우, 통신이 끝나기 전까지 버튼의 터치 자체를 disable 시켜 버립니다.

여튼, 코드 자체는 나쁘지 않은 것 같아서 참고만 해주시고, 차차 고도화해가도록 해요.ㅋㅋ

from sos.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.