Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web: go to post detail page if main page not at first when create post success #179

Merged
merged 1 commit into from
Jul 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions web/src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,36 @@ const loadPosts = () => {
};

const onPostSuccess = (post: Item.PostProps) => {
let items = [];
let length = list.value.length;
if (length == pageSize.value) {
// 如果不在第一页,需要跳转到详情页面
if (page.value != 1) {
router.push({
name: 'post',
query: {
id: post.id,
},
});
return;
}

// 如果实在第一页,就地插入新推文到文章列表中
let items = [];
let length = list.value.length;
if (length == pageSize.value) {
length--;
}
var i = 0;
for (;i < length; i++) {
}
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(post);
for (;i < length; i++) {
items.push(list.value[i]);
}
list.value = items;
}
list.value = items;
};

const updatePage = (p: number) => {
Expand Down