Comments (2)
DetailVC 부분에 하기 코드 추가해서 수정하였습니다.
해당질문에 해당유저가 좋아요한 카운트가 0일 때는 종전과 그대로 데이터가 추가됩니다.
이때 빠른속도로 클릭했을 때 데이터가 받아들이는 속도 차이에 의해서 똑같은 Like
데이터가 중복입력될 수 있습니다.
따라서, 삭제할 때 같은 데이터가 있다면 모두 지워져야, 유저시선에서는 좋아요를 취소했음에도 불구하고 별표가 바뀌지 않는 에러를 방지할 수 있습니다.
첨삭/수정한 코드는 다음과 같습니다.
// 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)
}
}
이렇게 하면 한번만 취소해도 모든 중복된 좋아요가 지워지게 됩니다.
from sos.
오오. 좋은(?) 버그네요. 굳굳입니다.
한가지 + 하자면, 보통 이런 버그 혹은 고도화에서는 통신 단에서 해결하지 않고, UI 단에서 해결하는 데요.
이 같은 경우에는, 좋아요 버튼을 한번 눌렀을 경우, 통신이 끝나기 전까지 버튼의 터치 자체를 disable
시켜 버립니다.
여튼, 코드 자체는 나쁘지 않은 것 같아서 참고만 해주시고, 차차 고도화해가도록 해요.ㅋㅋ
from sos.
Related Issues (20)
- 보영 - 파이어베이스 이벤트를 이용해 유저들의 캐릭터 선택 수 기록되게 하기
- 보영 - DetailView 의 이미지 UI 문제 (로드 후 자신의 Superview 보다 커지는 문제) HOT 1
- 재성 - 구글 애드센스 코드, 실제 구현 코드로 삽입하기 HOT 1
- 재성 - 노란색 경고 줄이기
- 재성 - 디테일 뷰, 공유하기/즐겨찾기 버튼 간격 띄우기 HOT 1
- 재성 - 디테일 뷰: 공유하기 기능에서 질문/답변 텍스트 함께 태우는 기능으로 실제 구현 코드로 삽입하기 HOT 1
- 보영 - Favorite 관련 버그(?). HOT 2
- 선미 - 컨텐츠 준비하기 HOT 2
- 보영 - 콘텐츠 만들기 HOT 5
- 재성 - 검색으로 들어간 디테일 뷰, 공유 기능 구현 ( 수요일까지 ) HOT 1
- 재성 - 출시 직전에 파이어베이스 plist 교체하기 HOT 2
- 재성 - 개발자 소개 / 캐릭터 소개 텍스트 준비하기 HOT 3
- 재성 - 콘텐츠 만들기 ( 매일 댓글 달기 ) HOT 1
- 선미 - 이미지 클릭하면 새창띄우기 HOT 1
- 재성 - SOS, 테스트플라이트 올리기 ( 개발자계정에 앱 등록 ) HOT 2
- 보영 - 파이어베이스에 질문당 `keyword` 데이터를 추가해서 검색할 키워드 String을 적을 것 HOT 2
- // 첫번째 Reject 대응 HOT 4
- 보영 - 노티피케이션 기능 추가 by Firebase
- 재성 - 디테일 뷰, 콘텐츠 부분에 마크다운 적용시키기 ( 오픈소스, 심플마크다운파서 적용 )
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sos.