Merge pull request 'Fixes #9350' (#9495) from yawhn/elreqkey:develop into develop

Reviewed-on: https://codeberg.org/calckey/calckey/pulls/9495
This commit is contained in:
Kainoa Kanter 2023-01-20 00:19:16 +00:00
commit 8e79ab69b0
5 changed files with 136 additions and 118 deletions

View file

@ -1,5 +1,5 @@
<template> <template>
<MkPagination ref="pagingComponent" :pagination="pagination"> <MkPagination ref="pagingComponent" :pagination="pagination" disableReload="true">
<template #empty> <template #empty>
<div class="_fullinfo"> <div class="_fullinfo">
<img src="/static-assets/badges/info.png" class="_ghost" alt="Info"/> <img src="/static-assets/badges/info.png" class="_ghost" alt="Info"/>

View file

@ -15,14 +15,17 @@
<div v-else ref="rootEl"> <div v-else ref="rootEl">
<div v-show="pagination.reversed && more" key="_more_" class="cxiknjgy _gap"> <div v-show="pagination.reversed && more" key="_more_" class="cxiknjgy _gap">
<MkButton v-if="!moreFetching" class="button" :disabled="moreFetching" :style="{ cursor: moreFetching ? 'wait' : 'pointer' }" primary @click="fetchMoreAhead"> <MkButton v-if="!moreFetching" class="button" :disabled="moreFetching"
:style="{ cursor: moreFetching ? 'wait' : 'pointer' }" primary @click="fetchMoreAhead">
{{ i18n.ts.loadMore }} {{ i18n.ts.loadMore }}
</MkButton> </MkButton>
<MkLoading v-else class="loading" /> <MkLoading v-else class="loading" />
</div> </div>
<slot :items="items"></slot> <slot :items="items"></slot>
<div v-show="!pagination.reversed && more" key="_more_" class="cxiknjgy _gap"> <div v-show="!pagination.reversed && more" key="_more_" class="cxiknjgy _gap">
<MkButton v-if="!moreFetching" v-appear="($store.state.enableInfiniteScroll && !disableAutoLoad) ? fetchMore : null" class="button" :disabled="moreFetching" :style="{ cursor: moreFetching ? 'wait' : 'pointer' }" primary @click="fetchMore"> <MkButton v-if="!moreFetching"
v-appear="($store.state.enableInfiniteScroll && !disableAutoLoad) ? fetchMore : null" class="button"
:disabled="moreFetching" :style="{ cursor: moreFetching ? 'wait' : 'pointer' }" primary @click="fetchMore">
{{ i18n.ts.loadMore }} {{ i18n.ts.loadMore }}
</MkButton> </MkButton>
<MkLoading v-else class="loading" /> <MkLoading v-else class="loading" />
@ -66,6 +69,7 @@ const props = withDefaults(defineProps<{
disableAutoLoad?: boolean; disableAutoLoad?: boolean;
displayLimit?: number; displayLimit?: number;
externalItemArray?: Ref<Array<any>>; externalItemArray?: Ref<Array<any>>;
disableReload?: boolean;
}>(), { }>(), {
displayLimit: 30, displayLimit: 30,
}); });
@ -87,6 +91,7 @@ const backed = ref(false); // 遡り中か否か
const isBackTop = ref(false); const isBackTop = ref(false);
const empty = computed(() => items.value.length === 0); const empty = computed(() => items.value.length === 0);
const error = ref(false); const error = ref(false);
const alreadyInitedOnce = ref(false);
const init = async (): Promise<void> => { const init = async (): Promise<void> => {
queue.value = []; queue.value = [];
@ -107,14 +112,17 @@ const init = async (): Promise<void> => {
if (!props.pagination.noPaging && (res.length > (props.pagination.limit || 10))) { if (!props.pagination.noPaging && (res.length > (props.pagination.limit || 10))) {
res.pop(); res.pop();
items.value = props.pagination.reversed ? [...res].reverse() : res; items.value = props.pagination.reversed ? [...res].reverse() : res;
if (props.externalItemArray) {
props.externalItemArray.value = items.value;
}
more.value = true; more.value = true;
} else { } else {
items.value = props.pagination.reversed ? [...res].reverse() : res; items.value = props.pagination.reversed ? [...res].reverse() : res;
more.value = false;
}
if (props.externalItemArray) { if (props.externalItemArray) {
props.externalItemArray.value = items.value; props.externalItemArray.value = items.value;
} }
more.value = false;
}
offset.value = res.length; offset.value = res.length;
error.value = false; error.value = false;
fetching.value = false; fetching.value = false;
@ -188,14 +196,17 @@ const fetchMore = async (): Promise<void> => {
if (res.length > SECOND_FETCH_LIMIT) { if (res.length > SECOND_FETCH_LIMIT) {
res.pop(); res.pop();
items.value = props.pagination.reversed ? [...res].reverse().concat(items.value) : items.value.concat(res); items.value = props.pagination.reversed ? [...res].reverse().concat(items.value) : items.value.concat(res);
if (props.externalItemArray) {
props.externalItemArray.value = items.value;
}
more.value = true; more.value = true;
} else { } else {
items.value = props.pagination.reversed ? [...res].reverse().concat(items.value) : items.value.concat(res); items.value = props.pagination.reversed ? [...res].reverse().concat(items.value) : items.value.concat(res);
more.value = false;
}
if (props.externalItemArray) { if (props.externalItemArray) {
props.externalItemArray.value = items.value; props.externalItemArray.value = items.value;
} }
more.value = false;
}
offset.value += res.length; offset.value += res.length;
moreFetching.value = false; moreFetching.value = false;
}, err => { }, err => {
@ -221,14 +232,17 @@ const fetchMoreAhead = async (): Promise<void> => {
if (res.length > SECOND_FETCH_LIMIT) { if (res.length > SECOND_FETCH_LIMIT) {
res.pop(); res.pop();
items.value = props.pagination.reversed ? [...res].reverse().concat(items.value) : items.value.concat(res); items.value = props.pagination.reversed ? [...res].reverse().concat(items.value) : items.value.concat(res);
if (props.externalItemArray) {
props.externalItemArray.value = items.value;
}
more.value = true; more.value = true;
} else { } else {
items.value = props.pagination.reversed ? [...res].reverse().concat(items.value) : items.value.concat(res); items.value = props.pagination.reversed ? [...res].reverse().concat(items.value) : items.value.concat(res);
more.value = false;
}
if (props.externalItemArray) { if (props.externalItemArray) {
props.externalItemArray.value = items.value; props.externalItemArray.value = items.value;
} }
more.value = false;
}
offset.value += res.length; offset.value += res.length;
moreFetching.value = false; moreFetching.value = false;
}, err => { }, err => {
@ -278,17 +292,6 @@ const prepend = (item: Item): void => {
// Prepend the item // Prepend the item
items.value.unshift(item); items.value.unshift(item);
if (props.externalItemArray) props.externalItemArray.value.unshift(item); if (props.externalItemArray) props.externalItemArray.value.unshift(item);
//
if (items.value.length >= props.displayLimit) {
// Vue 3.2
//this.items = items.value.slice(0, props.displayLimit);
while (items.value.length >= props.displayLimit) {
items.value.pop();
if(props.externalItemArray) props.externalItemArray.value.pop();
}
more.value = true;
}
} else { } else {
queue.value.push(item); queue.value.push(item);
onScrollTop(rootEl.value, () => { onScrollTop(rootEl.value, () => {
@ -308,7 +311,8 @@ const append = (item: Item): void => {
const removeItem = (finder: (item: Item) => boolean): boolean => { const removeItem = (finder: (item: Item) => boolean): boolean => {
const i = items.value.findIndex(finder); const i = items.value.findIndex(finder);
if (i === -1) { const j = props.externalItemArray?.findIndex(finder);
if (i === -1 && j === -1) {
return false; return false;
} }
@ -319,7 +323,8 @@ const removeItem = (finder: (item: Item) => boolean): boolean => {
const updateItem = (id: Item['id'], replacer: (old: Item) => Item): boolean => { const updateItem = (id: Item['id'], replacer: (old: Item) => Item): boolean => {
const i = items.value.findIndex(item => item.id === id); const i = items.value.findIndex(item => item.id === id);
if (i === -1) { const j = props.externalItemArray?.findIndex(item => item.id === id);
if (i === -1 && j === -1) {
return false; return false;
} }
@ -341,10 +346,14 @@ init();
onActivated(() => { onActivated(() => {
isBackTop.value = false; isBackTop.value = false;
if(alreadyInitedOnce.value && (!props.disableReload || !props.disableReload.value)) {
reload();
}
}); });
onDeactivated(() => { onDeactivated(() => {
isBackTop.value = window.scrollY === 0; isBackTop.value = window.scrollY === 0;
alreadyInitedOnce.value = true;
}); });
defineExpose({ defineExpose({
@ -365,6 +374,7 @@ defineExpose({
.fade-leave-active { .fade-leave-active {
transition: opacity 0.15s ease; transition: opacity 0.15s ease;
} }
.fade-enter-from, .fade-enter-from,
.fade-leave-to { .fade-leave-to {
opacity: 0; opacity: 0;

View file

@ -1,32 +1,36 @@
<template> <template>
<MkStickyContainer> <MkStickyContainer>
<template #header><MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs"/></template> <template #header>
<MkPageHeader v-model:tab="tab" :actions="headerActions" :tabs="headerTabs" />
</template>
<div> <div>
<MkSpacer :content-max="800"> <MkSpacer :content-max="800">
<swiper <swiper :modules="[Virtual]" :space-between="20" :virtual="true"
:modules="[Virtual]" :allow-touch-move="!(deviceKind === 'desktop' && !defaultStore.state.swipeOnDesktop)" @swiper="setSwiperRef"
:space-between="20" @slide-change="onSlideChange">
:virtual="true"
:allow-touch-move="!(deviceKind === 'desktop' && !defaultStore.state.swipeOnDesktop)"
@swiper="setSwiperRef"
@slide-change="onSlideChange"
>
<swiper-slide> <swiper-slide>
<div class="_content yweeujhr dms"> <div class="_content yweeujhr dms">
<MkButton primary class="start" @click="startUser"><i class="ph-plus-bold ph-lg"></i> {{ i18n.ts.startMessaging }}</MkButton> <MkButton primary class="start" @click="startUser"><i class="ph-plus-bold ph-lg"></i> {{
<MkPagination v-slot="{}" :externalItemArray="messages" :pagination="dmsPagination"> i18n.ts.startMessaging
<MkChatPreview v-for="message in messages" :key="message.id" class="yweeujhr message _block" :message="message"/> }}</MkButton>
<MkPagination v-slot="{ items }" :pagination="dmsPagination">
<MkChatPreview v-for="message in items" :key="message.id" class="yweeujhr message _block"
:message="message" />
</MkPagination> </MkPagination>
</div> </div>
</swiper-slide> </swiper-slide>
<swiper-slide> <swiper-slide>
<div class="_content yweeujhr groups"> <div class="_content yweeujhr groups">
<div class="groupsbuttons"> <div class="groupsbuttons">
<MkButton primary class="start" :link="true" to="/my/groups"><i class="ph-user-circle-gear-bold ph-lg"></i> {{ i18n.ts.manageGroups }}</MkButton> <MkButton primary class="start" :link="true" to="/my/groups"><i
<MkButton primary class="start" @click="startGroup"><i class="ph-plus-bold ph-lg"></i> {{ i18n.ts.startMessaging }}</MkButton> class="ph-user-circle-gear-bold ph-lg"></i> {{ i18n.ts.manageGroups }}</MkButton>
<MkButton primary class="start" @click="startGroup"><i class="ph-plus-bold ph-lg"></i> {{
i18n.ts.startMessaging
}}</MkButton>
</div> </div>
<MkPagination v-slot="{}" :externalItemArray="groupMessages" :pagination="groupsPagination"> <MkPagination v-slot="{ items }" :pagination="groupsPagination">
<MkChatPreview v-for="message in groupMessages" :key="message.id" class="yweeujhr message _block" :message="message"/> <MkChatPreview v-for="message in items" :key="message.id" class="yweeujhr message _block"
:message="message" />
</MkPagination> </MkPagination>
</div> </div>
</swiper-slide> </swiper-slide>
@ -37,7 +41,7 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { markRaw, onMounted, onUnmounted, watch } from 'vue'; import { markRaw, onMounted, onUnmounted, watch, computed } from 'vue';
import * as Acct from 'calckey-js/built/acct'; import * as Acct from 'calckey-js/built/acct';
import { Virtual } from 'swiper'; import { Virtual } from 'swiper';
import { Swiper, SwiperSlide } from 'swiper/vue'; import { Swiper, SwiperSlide } from 'swiper/vue';
@ -58,8 +62,9 @@ import 'swiper/scss/virtual';
const router = useRouter(); const router = useRouter();
let messages = $ref([]); let messages = $ref([]);
let groupMessages = $ref([]);
let connection = $ref(null); let connection = $ref(null);
let paginationComponentUser = $ref<InstanceType<typeof MkPagination>>();
let paginationComponentGroup = $ref<InstanceType<typeof MkPagination>>();
const tabs = ['dms', 'groups']; const tabs = ['dms', 'groups'];
let tab = $ref(tabs[0]); let tab = $ref(tabs[0]);
@ -89,17 +94,19 @@ definePageMetadata({
const dmsPagination = { const dmsPagination = {
endpoint: 'messaging/history' as const, endpoint: 'messaging/history' as const,
limit: 15, limit: 20,
params: { params: computed(() => ({
group: false, group: false,
}, })),
offsetMode: true,
}; };
const groupsPagination = { const groupsPagination = {
endpoint: 'messaging/history' as const, endpoint: 'messaging/history' as const,
limit: 5, limit: 10,
params: { params: computed(() => ({
group: true, group: true,
}, })),
offsetMode: true,
}; };
function onMessage(message): void { function onMessage(message): void {
@ -110,9 +117,10 @@ function onMessage(message): void {
messages.unshift(message); messages.unshift(message);
} else if (message.groupId) { } else if (message.groupId) {
groupMessages = groupMessages.filter(m => m.groupId !== message.groupId); messages = messages.filter(m => m.groupId !== message.groupId);
groupMessages.unshift(message); messages.unshift(message);
} }
forceRerender();
} }
function onRead(ids): void { function onRead(ids): void {

View file

@ -460,7 +460,7 @@ export const routes = [
{ {
path: "/ads", path: "/ads",
name: "ads", name: "ads",
component: page(() => import("./pages/admin/ads.vue")), component: page(() => import("./pages/admin/promotions.vue")),
}, },
{ {
path: "/database", path: "/database",