Skip to content

Commit

Permalink
MkPaginationのリファクタリング (#360)
Browse files Browse the repository at this point in the history
* propsからpageElを削除

* Pagingのインポートが型であると明記
  • Loading branch information
adzukimame authored Dec 8, 2024
1 parent 103109c commit a1ed595
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/frontend/src/components/MkChannelList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ SPDX-License-Identifier: AGPL-3.0-only

<script lang="ts" setup>
import MkChannelPreview from '@/components/MkChannelPreview.vue';
import MkPagination, { Paging } from '@/components/MkPagination.vue';
import MkPagination, { type Paging } from '@/components/MkPagination.vue';
import { i18n } from '@/i18n.js';
import { infoImageUrl } from '@/instance.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/MkNotes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { shallowRef } from 'vue';
import type { ComponentExposed } from 'vue-component-type-helpers';
import MkNote from '@/components/MkNote.vue';
import MkDateSeparatedList from '@/components/MkDateSeparatedList.vue';
import MkPagination, { Paging } from '@/components/MkPagination.vue';
import MkPagination, { type Paging } from '@/components/MkPagination.vue';
import { i18n } from '@/i18n.js';
import { infoImageUrl } from '@/instance.js';

Expand Down
17 changes: 7 additions & 10 deletions packages/frontend/src/components/MkPagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ export type Paging<E extends keyof MisskeyEndpoints = keyof MisskeyEndpoints> =
reversed?: boolean;

offsetMode?: boolean;

pageEl?: HTMLElement;
};
</script>

Expand Down Expand Up @@ -141,8 +139,7 @@ const {
enableInfiniteScroll,
} = defaultStore.reactiveState;

const contentEl = computed(() => props.pagination.pageEl ?? rootEl.value);
const scrollableElement = computed(() => contentEl.value ? getScrollContainer(contentEl.value) : document.body);
const scrollableElement = computed(() => rootEl.value ? getScrollContainer(rootEl.value) : document.body);

const visibility = useDocumentVisibility();

Expand Down Expand Up @@ -173,13 +170,13 @@ watch(rootEl, () => {
});
});

watch([backed, contentEl], () => {
watch([backed, rootEl], () => {
if (!backed.value) {
if (!contentEl.value) return;
if (!rootEl.value) return;

scrollRemove.value = props.pagination.reversed
? onScrollBottom(contentEl.value, executeQueue, TOLERANCE)
: onScrollTop(contentEl.value, (topVisible) => { if (topVisible) executeQueue(); }, TOLERANCE);
? onScrollBottom(rootEl.value, executeQueue, TOLERANCE)
: onScrollTop(rootEl.value, (topVisible) => { if (topVisible) executeQueue(); }, TOLERANCE);
} else {
if (scrollRemove.value) scrollRemove.value();
scrollRemove.value = null;
Expand Down Expand Up @@ -338,7 +335,7 @@ const appearFetchMoreAhead = async (): Promise<void> => {
fetchMoreAppearTimeout();
};

const isTop = (): boolean => isBackTop.value || (props.pagination.reversed ? isBottomVisible : isTopVisible)(contentEl.value!, TOLERANCE);
const isTop = (): boolean => isBackTop.value || (props.pagination.reversed ? isBottomVisible : isTopVisible)(rootEl.value!, TOLERANCE);

watch(visibility, () => {
if (visibility.value === 'hidden') {
Expand Down Expand Up @@ -436,7 +433,7 @@ onDeactivated(() => {
});

function toBottom() {
scrollToBottom(contentEl.value!);
scrollToBottom(rootEl.value!);
}

onBeforeMount(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/MkTimeline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ SPDX-License-Identifier: AGPL-3.0-only
import { computed, watch, onUnmounted, provide, shallowRef, useTemplateRef } from 'vue';
import type { ChannelConnection, Channels, Endpoints as MisskeyEndpoints } from 'misskey-js';
import type { BasicTimelineType } from '@/timelines.js';
import type { Paging } from '@/components/MkPagination.vue';
import MkNotes from '@/components/MkNotes.vue';
import MkPullToRefresh from '@/components/MkPullToRefresh.vue';
import { useStream } from '@/stream.js';
import { $i } from '@/account.js';
import { defaultStore } from '@/store.js';
import { Paging } from '@/components/MkPagination.vue';

const props = withDefaults(defineProps<{
src: BasicTimelineType | 'mentions' | 'directs' | 'list' | 'antenna' | 'channel';
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/MkUserList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<script lang="ts" setup generic="E extends keyof Endpoints = keyof Endpoints">
import type { Endpoints } from 'misskey-js/api.types.js';
import MkUserInfo from '@/components/MkUserInfo.vue';
import MkPagination, { Paging } from '@/components/MkPagination.vue';
import MkPagination, { type Paging } from '@/components/MkPagination.vue';
import { i18n } from '@/i18n.js';
import { infoImageUrl } from '@/instance.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/pages/about.federation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import { computed, ref } from 'vue';
import type { Endpoints } from 'misskey-js';
import MkInput from '@/components/MkInput.vue';
import MkSelect from '@/components/MkSelect.vue';
import MkPagination, { Paging } from '@/components/MkPagination.vue';
import MkPagination, { type Paging } from '@/components/MkPagination.vue';
import MkInstanceCardMini from '@/components/MkInstanceCardMini.vue';
import FormSplit from '@/components/form/split.vue';
import { i18n } from '@/i18n.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/pages/admin/invites.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import MkFolder from '@/components/MkFolder.vue';
import MkSelect from '@/components/MkSelect.vue';
import MkInput from '@/components/MkInput.vue';
import MkSwitch from '@/components/MkSwitch.vue';
import MkPagination, { Paging } from '@/components/MkPagination.vue';
import MkPagination, { type Paging } from '@/components/MkPagination.vue';
import MkInviteCode from '@/components/MkInviteCode.vue';
import { definePageMetadata } from '@/scripts/page-metadata.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/pages/drive.file.notes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ SPDX-License-Identifier: AGPL-3.0-only

<script lang="ts" setup>
import { ref, computed } from 'vue';
import type { Paging } from '@/components/MkPagination.vue';
import { i18n } from '@/i18n.js';
import { Paging } from '@/components/MkPagination.vue';
import MkInfo from '@/components/MkInfo.vue';
import MkNotes from '@/components/MkNotes.vue';

Expand Down

0 comments on commit a1ed595

Please sign in to comment.