Skip to content

Commit

Permalink
Feat: 댓글에도 동일한 속도향상 로직 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
sangohkim committed Feb 16, 2024
1 parent 7d7168f commit b959398
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 19 deletions.
54 changes: 41 additions & 13 deletions lib/pages/post_view_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -754,15 +754,17 @@ class _PostViewPageState extends State<PostViewPage> {
InkWell(
onTap: () async {
// API 요청 이전에 먼저 state를 변경한 뒤에 요청 결과에 따라 처리하기
ArticleController(model: _article, userProvider: userProvider).setVote(true);
ArticleController(model: _article, userProvider: userProvider)
.setVote(true);
_updateState();
bool res = await ArticleController(
model: _article,
userProvider: userProvider,
).posVote();
debugPrint('좋아요 결과 ${res}');
if (!res) {
ArticleController(model: _article, userProvider: userProvider).setVote(true);
ArticleController(model: _article, userProvider: userProvider)
.setVote(true);
_updateState();
}
},
Expand All @@ -783,15 +785,17 @@ class _PostViewPageState extends State<PostViewPage> {
InkWell(
onTap: () async {
// API 요청 이전에 먼저 state를 변경한 뒤에 요청 결과에 따라 처리하기
ArticleController(model: _article, userProvider: userProvider).setVote(false);
ArticleController(model: _article, userProvider: userProvider)
.setVote(false);
_updateState();
bool res = await ArticleController(
model: _article,
userProvider: userProvider,
).negVote();
debugPrint('싫어요 결과 ${res}');
if (!res) {
ArticleController(model: _article, userProvider: userProvider).setVote(false);
ArticleController(model: _article, userProvider: userProvider)
.setVote(false);
_updateState();
}
},
Expand Down Expand Up @@ -1345,13 +1349,25 @@ class _PostViewPageState extends State<PostViewPage> {
child: Row(
children: [
InkWell(
onTap: () {
onTap: () async {
// API 요청 이전에 먼저 state를 변경한 뒤에 요청 결과에 따라 처리하기
CommentController(
model: curComment,
model: curComment,
userProvider: userProvider)
.setVote(true);
_updateState();
bool res = await ArticleController(
model: _article,
userProvider: userProvider,
).posVote().then((result) {
if (result) _updateState();
});
).posVote();
debugPrint('좋아요 결과 ${res}');
if (!res) {
CommentController(
model: curComment,
userProvider: userProvider)
.setVote(true);
_updateState();
}
},
child: _buildVoteIcons(true, curComment.my_vote,
ColorsInfo.posVote, 11.52, 12.57),
Expand All @@ -1370,12 +1386,24 @@ class _PostViewPageState extends State<PostViewPage> {
const SizedBox(width: 12),
InkWell(
onTap: () async {
// API 요청 이전에 먼저 state를 변경한 뒤에 요청 결과에 따라 처리하기
CommentController(
model: curComment,
model: curComment,
userProvider: userProvider)
.setVote(false);
_updateState();
bool res = await ArticleController(
model: _article,
userProvider: userProvider,
).negVote().then((result) {
if (result) _updateState();
});
).negVote();
debugPrint('좋아요 결과 ${res}');
if (!res) {
CommentController(
model: curComment,
userProvider: userProvider)
.setVote(false);
_updateState();
}
},
child: _buildVoteIcons(
false,
Expand Down
10 changes: 4 additions & 6 deletions lib/utils/post_view_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,13 @@ class CommentController {
var cancelRes = await userProvider.postApiRes(
"comments/$id/vote_cancel/",
);
if (cancelRes.statusCode != 200) return false;
if (cancelRes == null || cancelRes.statusCode != 200) return false;
} else {
var postRes = await userProvider.postApiRes(
"comments/$id/vote_positive/",
);
if (postRes.statusCode != 200) return false;
if (postRes == null || postRes.statusCode != 200) return false;
}
setVote(true);
return true;
}

Expand All @@ -285,14 +284,13 @@ class CommentController {
var cancelRes = await userProvider.postApiRes(
"comments/$id/vote_cancel/",
);
if (cancelRes.statusCode != 200) return false;
if (cancelRes == null || cancelRes.statusCode != 200) return false;
} else {
var postRes = await userProvider.postApiRes(
"comments/$id/vote_negative/",
);
if (postRes.statusCode != 200) return false;
if (postRes == null || postRes.statusCode != 200) return false;
}
setVote(false);
return true;
}

Expand Down

0 comments on commit b959398

Please sign in to comment.