fix issues

This commit is contained in:
Rogee
2024-09-21 13:52:47 +08:00
parent 5aecfe6379
commit f8a7e87965
13 changed files with 156 additions and 51 deletions

View File

@@ -16,16 +16,31 @@ import ListItem from "@/components/ListItem.vue";
import { getChannel } from "@/services/channels";
import { getChannelMessages } from "@/services/messages";
import { onMounted, ref } from "vue";
import { useRoute } from "vue-router";
import { useRoute, useRouter } from "vue-router";
const route = useRoute();
const router = useRouter();
const channel = ref({});
const messages = ref([]);
const loadMore = async () => {
const items = await getChannelMessages(route.params.channel, { offset: messages.value[messages.value.length - 1].ID });
messages.value.push(...items);
// router goto next page
// offset is last message ID
const offset = messages.value[messages.value.length - 1].ID
router.push({
name: "channel-messages",
params: {
channel: route.params.channel,
offset: offset,
},
});
messages.value = await getChannelMessages(route.params.channel, { offset: offset });
console.log("messages", messages.value);
// page scroll to top with animation
window.scrollTo({ top: 0, behavior: "smooth" });
}
onMounted(async () => {
@@ -34,7 +49,7 @@ onMounted(async () => {
console.log("channel", channel.value);
// get channel messages
messages.value = await getChannelMessages(route.params.channel);
messages.value = await getChannelMessages(route.params.channel, { offset: route.params.offset });
console.log("messages", messages.value);
});
</script>