Merge pull request #177 from alimy/jc/alimy

optimize #176 change reload page logic just for simple
pull/181/head
Michael Li 2 years ago committed by GitHub
commit 7151d2a3fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -103,8 +103,11 @@ func tagsFrom(originTags []string) []string {
// CreatePost 创建文章 // CreatePost 创建文章
// TODO: 推文+推文内容需要在一个事务中添加,后续优化 // TODO: 推文+推文内容需要在一个事务中添加,后续优化
func CreatePost(c *gin.Context, userID int64, param PostCreationReq) (post *model.Post, err error) { func CreatePost(c *gin.Context, userID int64, param PostCreationReq) (*model.PostFormated, error) {
var mediaContents []string var (
err error
mediaContents []string
)
defer func() { defer func() {
if err != nil { if err != nil {
@ -113,12 +116,12 @@ func CreatePost(c *gin.Context, userID int64, param PostCreationReq) (post *mode
}() }()
if mediaContents, err = persistMediaContents(param.Contents); err != nil { if mediaContents, err = persistMediaContents(param.Contents); err != nil {
return return nil, err
} }
ip := c.ClientIP() ip := c.ClientIP()
tags := tagsFrom(param.Tags) tags := tagsFrom(param.Tags)
post = &model.Post{ post := &model.Post{
UserID: userID, UserID: userID,
Tags: strings.Join(tags, ","), Tags: strings.Join(tags, ","),
IP: ip, IP: ip,
@ -187,7 +190,11 @@ func CreatePost(c *gin.Context, userID int64, param PostCreationReq) (post *mode
// 推送Search // 推送Search
PushPostToSearch(post) PushPostToSearch(post)
return post, nil formatedPosts, err := ds.RevampPosts([]*model.PostFormated{post.Format()})
if err != nil {
return nil, err
}
return formatedPosts[0], nil
} }
func DeletePost(user *model.User, id int64) *errcode.Error { func DeletePost(user *model.User, id int64) *errcode.Error {

@ -84,9 +84,24 @@ const loadPosts = () => {
}; };
const onPostSuccess = (post: Item.PostProps) => { const onPostSuccess = (post: Item.PostProps) => {
setTimeout(() => { let items = [];
loadPosts(); let length = list.value.length;
}, 50); if (length == pageSize.value) {
length--;
}
var i = 0;
for (;i < length; i++) {
let item: Item.PostProps = list.value[i];
if (!item.is_top) {
break;
}
items.push(item);
}
items.push(post);
for (;i < length; i++) {
items.push(list.value[i]);
}
list.value = items;
}; };
const updatePage = (p: number) => { const updatePage = (p: number) => {

Loading…
Cancel
Save