switch comment like
This commit is contained in:
parent
cf14565825
commit
b32cc569e3
|
@ -8,7 +8,7 @@ require (
|
|||
github.com/go-flutter-desktop/plugins/url_launcher v0.1.2
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20201108214237-06ea97f0c265
|
||||
github.com/miguelpruivo/flutter_file_picker/go v0.0.0-20210622152105-9f0a811028a0
|
||||
github.com/niuhuan/pica-go v0.0.0-20211008032829-544a58c56bee
|
||||
github.com/niuhuan/pica-go v0.0.0-20211102035530-65029bd4ee97
|
||||
github.com/pkg/errors v0.9.1
|
||||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b
|
||||
golang.org/x/mobile v0.0.0-20210924032853-1c027f395ef7 // indirect
|
||||
|
|
|
@ -37,6 +37,8 @@ github.com/miguelpruivo/flutter_file_picker/go v0.0.0-20210622152105-9f0a811028a
|
|||
github.com/miguelpruivo/flutter_file_picker/go v0.0.0-20210622152105-9f0a811028a0/go.mod h1:csuW+TFyYKtiUwNvcvhcpyX4quPI7Pvv0SUogdqCW4I=
|
||||
github.com/niuhuan/pica-go v0.0.0-20211008032829-544a58c56bee h1:SewxTGOkoJ3JUmLLQ1RXUcqLdifT5502QZQl09eCGL8=
|
||||
github.com/niuhuan/pica-go v0.0.0-20211008032829-544a58c56bee/go.mod h1:fx2m+OgMeEZf6/TrfblV9i85SjPsOGbnjIL2gohxP4M=
|
||||
github.com/niuhuan/pica-go v0.0.0-20211102035530-65029bd4ee97 h1:wlsmZVsLrZ/dB1KzyRl3TR6vRa6eefVE/16LnSHrQs8=
|
||||
github.com/niuhuan/pica-go v0.0.0-20211102035530-65029bd4ee97/go.mod h1:fx2m+OgMeEZf6/TrfblV9i85SjPsOGbnjIL2gohxP4M=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
|
|
|
@ -425,6 +425,22 @@ func postChildComment(params string) (string, error) {
|
|||
return "", nil
|
||||
}
|
||||
|
||||
func switchLikeComment(params string) (string, error) {
|
||||
var paramsStruct struct {
|
||||
CommentId string `json:"commentId"`
|
||||
ComicId string `json:"comicId"`
|
||||
}
|
||||
json.Unmarshal([]byte(params), ¶msStruct)
|
||||
rsp, err := client.SwitchLikeComment(paramsStruct.CommentId)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
network_cache.RemoveCaches(fmt.Sprintf("COMMENT_CHILDREN$%s$%%", paramsStruct.CommentId))
|
||||
network_cache.RemoveCaches("MY_COMMENTS$%")
|
||||
network_cache.RemoveCaches(fmt.Sprintf("COMMENTS$%s$%%", paramsStruct.ComicId))
|
||||
return *rsp, nil
|
||||
}
|
||||
|
||||
func myComments(pageStr string) (string, error) {
|
||||
page, err := strconv.Atoi(pageStr)
|
||||
if err != nil {
|
||||
|
|
|
@ -646,6 +646,8 @@ func FlatInvoke(method string, params string) (string, error) {
|
|||
return "", nil
|
||||
case "loadDownloadThreadCount":
|
||||
return strconv.Itoa(loadDownloadThreadCount()), nil
|
||||
case "switchLikeComment":
|
||||
return switchLikeComment(params)
|
||||
}
|
||||
return "", errors.New("method not found : " + method)
|
||||
}
|
||||
|
|
|
@ -600,4 +600,11 @@ class Method {
|
|||
return _flatInvoke("saveDownloadThreadCount", "$value");
|
||||
}
|
||||
|
||||
/// 喜欢/取消喜欢 一条评论
|
||||
Future switchLikeComment(String commentId, String comicId) {
|
||||
return _flatInvoke("switchLikeComment", {
|
||||
"commentId": commentId,
|
||||
"comicId": comicId,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ class _CommentScreenState extends State<CommentScreen> {
|
|||
),
|
||||
body: Column(
|
||||
children: [
|
||||
ComicCommentItem(widget.comment),
|
||||
ComicCommentItem(widget.comment, widget.comicId),
|
||||
Container(
|
||||
height: 3,
|
||||
color:
|
||||
|
@ -68,7 +68,7 @@ class _CommentScreenState extends State<CommentScreen> {
|
|||
}
|
||||
|
||||
Widget _buildComment(CommentChild e) {
|
||||
return ComicCommentItem(e);
|
||||
return ComicCommentItem(e, widget.comicId);
|
||||
}
|
||||
|
||||
Widget _buildPostComment() {
|
||||
|
|
|
@ -1,16 +1,27 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:pikapi/basic/Common.dart';
|
||||
import 'package:pikapi/basic/Entities.dart';
|
||||
import 'package:pikapi/basic/Method.dart';
|
||||
|
||||
import 'PicaAvatar.dart';
|
||||
|
||||
class ComicCommentItem extends StatelessWidget {
|
||||
class ComicCommentItem extends StatefulWidget {
|
||||
final String comicId;
|
||||
final Comment comment;
|
||||
|
||||
const ComicCommentItem(this.comment);
|
||||
const ComicCommentItem(this.comment, this.comicId);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _ComicCommentItem();
|
||||
}
|
||||
|
||||
class _ComicCommentItem extends State<ComicCommentItem> {
|
||||
var likeLoading = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var comment = widget.comment;
|
||||
var comicId = widget.comicId;
|
||||
var theme = Theme.of(context);
|
||||
var nameStyle = TextStyle(fontWeight: FontWeight.bold);
|
||||
var levelStyle = TextStyle(
|
||||
|
@ -93,22 +104,55 @@ class ComicCommentItem extends StatelessWidget {
|
|||
])
|
||||
: TextSpan(),
|
||||
WidgetSpan(child: Container(width: 12)),
|
||||
TextSpan(children: [
|
||||
WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
child: Icon(
|
||||
comment.isLiked
|
||||
? Icons.favorite
|
||||
: Icons.favorite_border,
|
||||
size: 13,
|
||||
color: theme.colorScheme.secondary
|
||||
.withOpacity(.7)),
|
||||
WidgetSpan(
|
||||
child: GestureDetector(
|
||||
onTap: () async {
|
||||
setState(() {
|
||||
likeLoading = true;
|
||||
});
|
||||
try {
|
||||
await method.switchLikeComment(
|
||||
comment.id,
|
||||
comicId,
|
||||
);
|
||||
setState(() {
|
||||
if (comment.isLiked) {
|
||||
comment.isLiked = false;
|
||||
comment.likesCount--;
|
||||
} else {
|
||||
comment.isLiked = true;
|
||||
comment.likesCount++;
|
||||
}
|
||||
});
|
||||
} catch (e, s) {
|
||||
defaultToast(context, "点赞失败");
|
||||
} finally {
|
||||
setState(() {
|
||||
likeLoading = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Text.rich(
|
||||
TextSpan(style: levelStyle, children: [
|
||||
WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
child: Icon(
|
||||
likeLoading
|
||||
? Icons.refresh
|
||||
: comment.isLiked
|
||||
? Icons.favorite
|
||||
: Icons.favorite_border,
|
||||
size: 13,
|
||||
color: theme.colorScheme.secondary
|
||||
.withOpacity(.7)),
|
||||
),
|
||||
WidgetSpan(child: Container(width: 5)),
|
||||
TextSpan(
|
||||
text: '${comment.likesCount}',
|
||||
),
|
||||
]),
|
||||
),
|
||||
WidgetSpan(child: Container(width: 5)),
|
||||
TextSpan(
|
||||
text: '${comment.likesCount}',
|
||||
),
|
||||
]),
|
||||
)),
|
||||
],
|
||||
)),
|
||||
],
|
||||
|
|
|
@ -59,7 +59,7 @@ class _ComicCommentListState extends State<ComicCommentList> {
|
|||
),
|
||||
);
|
||||
},
|
||||
child: ComicCommentItem(comment),
|
||||
child: ComicCommentItem(comment, widget.comicId),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue