✨ Pull to refresh
This commit is contained in:
		| @@ -1,5 +1,5 @@ | ||||
| <template> | ||||
|   <v-list-group value="channels"> | ||||
|   <v-list-group class="channels-list" value="channels"> | ||||
|     <template #activator="{ props }"> | ||||
|       <v-list-item | ||||
|         v-bind="props" | ||||
| @@ -28,7 +28,6 @@ | ||||
|  | ||||
| <script setup lang="ts"> | ||||
| import { useUserinfo } from "@/stores/userinfo" | ||||
| import { useRealms } from "@/stores/realms" | ||||
| import { useChannels } from "@/stores/channels" | ||||
|  | ||||
| const id = useUserinfo() | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| <template> | ||||
|   <v-list-group value="realms"> | ||||
|   <v-list-group class="realms-list" value="realms"> | ||||
|     <template #activator="{ props }"> | ||||
|       <v-list-item | ||||
|         v-bind="props" | ||||
|   | ||||
| @@ -35,8 +35,12 @@ | ||||
|       </v-toolbar> | ||||
|  | ||||
|       <div class="flex-grow-1"> | ||||
|         <v-list density="compact" :opened="drawerMini ? [] : expanded" | ||||
|                 @update:opened="(val) => expanded = val"> | ||||
|         <v-list | ||||
|           class="resources-list" | ||||
|           density="compact" | ||||
|           :opened="drawerMini ? [] : expanded" | ||||
|           @update:opened="(val) => expanded = val" | ||||
|         > | ||||
|           <channel-list /> | ||||
|           <v-divider class="border-opacity-75 my-2" /> | ||||
|           <realm-list /> | ||||
| @@ -83,14 +87,17 @@ | ||||
| </template> | ||||
|  | ||||
| <script setup lang="ts"> | ||||
| import { computed, ref } from "vue" | ||||
| import { useUserinfo, signout as signoutAccount } from "@/stores/userinfo" | ||||
| import { computed, onMounted, ref } from "vue" | ||||
| import { useUserinfo } from "@/stores/userinfo" | ||||
| import { useWellKnown } from "@/stores/wellKnown" | ||||
| import { useUI } from "@/stores/ui" | ||||
| import { useRealms } from "@/stores/realms" | ||||
| import { useChannels } from "@/stores/channels" | ||||
| import RealmList from "@/components/realms/RealmList.vue" | ||||
| import NotificationList from "@/components/users/NotificationList.vue" | ||||
| import ChannelList from "@/components/chat/channels/ChannelList.vue" | ||||
| import UserMenu from "@/components/users/UserMenu.vue" | ||||
| import PullToRefresh from "pulltorefreshjs" | ||||
|  | ||||
| const ui = useUI() | ||||
| const expanded = ref<string[]>(["channels"]) | ||||
| @@ -126,5 +133,18 @@ useWellKnown().readWellKnown() | ||||
|  | ||||
| const drawerOpen = ref(true) | ||||
| const drawerMini = ref(false) | ||||
|  | ||||
| onMounted(() => { | ||||
|   PullToRefresh.init({ | ||||
|     mainElement: ".resources-list", | ||||
|     triggerElement: ".resources-list", | ||||
|     onRefresh() { | ||||
|       return Promise.all([ | ||||
|         useRealms().list(), | ||||
|         useChannels().list() | ||||
|       ]) | ||||
|     } | ||||
|   }) | ||||
| }) | ||||
| </script> | ||||
|  | ||||
|   | ||||
| @@ -53,7 +53,7 @@ export const useNotifications = defineStore("notifications", () => { | ||||
|     }) | ||||
|     socket.addEventListener("close", (event) => { | ||||
|       console.warn("[NOTIFICATIONS] The listen websocket is disconnected... ", event.reason, event.code) | ||||
|       if(reconnectCount <= 3) { | ||||
|       if (reconnectCount <= 3) { | ||||
|         connect().then(() => { | ||||
|           console.warn("[NOTIFICATIONS] Now reconnecting!") | ||||
|           reconnectCount++ | ||||
| @@ -62,8 +62,10 @@ export const useNotifications = defineStore("notifications", () => { | ||||
|     }) | ||||
|     socket.addEventListener("message", (event) => { | ||||
|       const data = JSON.parse(event.data) | ||||
|       notifications.value.push(data) | ||||
|       total.value++ | ||||
|       if (!data.is_realtime) { | ||||
|         notifications.value.push(data) | ||||
|         total.value++ | ||||
|       } | ||||
|  | ||||
|       if (Capacitor.getPlatform() === "web") { | ||||
|         new Notification(data["subject"], { | ||||
|   | ||||
| @@ -16,9 +16,10 @@ | ||||
|  | ||||
| <script setup lang="ts"> | ||||
| import PostList from "@/components/posts/PostList.vue" | ||||
| import { onMounted, onUnmounted, reactive, ref } from "vue" | ||||
| import { request } from "@/scripts/request" | ||||
| import { reactive, ref } from "vue" | ||||
| import { useUI } from "@/stores/ui" | ||||
| import PullToRefresh, { type PullToRefreshInstance } from "pulltorefreshjs" | ||||
|  | ||||
| const pagination = reactive({ page: 1, pageSize: 10, total: 0 }) | ||||
|  | ||||
| @@ -63,6 +64,21 @@ async function readMore({ done }: any) { | ||||
| } | ||||
|  | ||||
| readPosts() | ||||
|  | ||||
| let refresher: PullToRefreshInstance | ||||
|  | ||||
| onMounted(() => { | ||||
|   refresher = PullToRefresh.init({ | ||||
|       mainElement: ".wrapper", | ||||
|       triggerElement: ".wrapper", | ||||
|       onRefresh() { | ||||
|         posts.value = [] | ||||
|         pagination.page = 0 | ||||
|         return readPosts() | ||||
|       } | ||||
|     }) | ||||
| }) | ||||
| onUnmounted(() => refresher.destory()) | ||||
| </script> | ||||
|  | ||||
| <style scoped> | ||||
|   | ||||
| @@ -32,7 +32,7 @@ | ||||
| </template> | ||||
|  | ||||
| <script setup lang="ts"> | ||||
| import { reactive, ref, watch } from "vue" | ||||
| import { onMounted, onUnmounted, reactive, ref, watch } from "vue" | ||||
| import { request } from "@/scripts/request" | ||||
| import { useRealms } from "@/stores/realms" | ||||
| import { useRoute } from "vue-router" | ||||
| @@ -41,6 +41,7 @@ import dompurify from "dompurify" | ||||
| import PostList from "@/components/posts/PostList.vue" | ||||
| import RealmAction from "@/components/realms/RealmAction.vue" | ||||
| import RealmMembers from "@/components/realms/RealmMembers.vue" | ||||
| import PullToRefresh, { type PullToRefreshInstance } from "pulltorefreshjs" | ||||
|  | ||||
| const route = useRoute() | ||||
| const realms = useRealms() | ||||
| @@ -68,11 +69,11 @@ async function readPosts() { | ||||
|   const res = await request( | ||||
|     "interactive", | ||||
|     `/api/feed?` + | ||||
|       new URLSearchParams({ | ||||
|         take: pagination.pageSize.toString(), | ||||
|         offset: ((pagination.page - 1) * pagination.pageSize).toString(), | ||||
|         realmId: route.params.realmId as string | ||||
|       }) | ||||
|     new URLSearchParams({ | ||||
|       take: pagination.pageSize.toString(), | ||||
|       offset: ((pagination.page - 1) * pagination.pageSize).toString(), | ||||
|       realmId: route.params.realmId as string | ||||
|     }) | ||||
|   ) | ||||
|   if (res.status !== 200) { | ||||
|     error.value = await res.text() | ||||
| @@ -122,6 +123,21 @@ watch(realms, (val) => { | ||||
| function parseContent(src: string): string { | ||||
|   return dompurify().sanitize(parse(src) as string) | ||||
| } | ||||
|  | ||||
| let refresher: PullToRefreshInstance | ||||
|  | ||||
| onMounted(() => { | ||||
|   refresher = PullToRefresh.init({ | ||||
|     mainElement: ".wrapper", | ||||
|     triggerElement: ".wrapper", | ||||
|     onRefresh() { | ||||
|       posts.value = [] | ||||
|       pagination.page = 0 | ||||
|       return readPosts() | ||||
|     } | ||||
|   }) | ||||
| }) | ||||
| onUnmounted(() => refresher.destory()) | ||||
| </script> | ||||
|  | ||||
| <style scoped> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user