mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-22 10:15:10 +00:00
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/599 Closes #622 Approved-by: Marie <2-Marie@users.noreply.activitypub.software> Approved-by: Julia Johannesen <julia@insertdomain.name>
This commit is contained in:
commit
d03c9f4b62
1 changed files with 12 additions and 6 deletions
|
@ -43,7 +43,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { computed, ComputedRef, isRef, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onDeactivated, ref, shallowRef, watch } from 'vue';
|
import { computed, ComputedRef, isRef, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onDeactivated, ref, shallowRef, watch, type Ref } from 'vue';
|
||||||
import * as Misskey from 'misskey-js';
|
import * as Misskey from 'misskey-js';
|
||||||
import * as os from '@/os.js';
|
import * as os from '@/os.js';
|
||||||
import { misskeyApi } from '@/scripts/misskey-api.js';
|
import { misskeyApi } from '@/scripts/misskey-api.js';
|
||||||
|
@ -199,11 +199,17 @@ watch(error, (n, o) => {
|
||||||
emit('status', n);
|
emit('status', n);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function getActualValue<T>(input: T|Ref<T>|undefined, defaultValue: T) : T {
|
||||||
|
if (!input) return defaultValue;
|
||||||
|
if (isRef(input)) return input.value;
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
async function init(): Promise<void> {
|
async function init(): Promise<void> {
|
||||||
items.value = new Map();
|
items.value = new Map();
|
||||||
queue.value = new Map();
|
queue.value = new Map();
|
||||||
fetching.value = true;
|
fetching.value = true;
|
||||||
const params = props.pagination.params ? isRef(props.pagination.params) ? props.pagination.params.value : props.pagination.params : {};
|
const params = getActualValue<Paging['params']>(props.pagination.params, {});
|
||||||
await misskeyApi<MisskeyEntity[]>(props.pagination.endpoint, {
|
await misskeyApi<MisskeyEntity[]>(props.pagination.endpoint, {
|
||||||
...params,
|
...params,
|
||||||
limit: props.pagination.limit ?? 10,
|
limit: props.pagination.limit ?? 10,
|
||||||
|
@ -239,8 +245,8 @@ const reload = (): Promise<void> => {
|
||||||
const fetchMore = async (): Promise<void> => {
|
const fetchMore = async (): Promise<void> => {
|
||||||
if (!more.value || fetching.value || moreFetching.value || items.value.size === 0) return;
|
if (!more.value || fetching.value || moreFetching.value || items.value.size === 0) return;
|
||||||
moreFetching.value = true;
|
moreFetching.value = true;
|
||||||
const params = props.pagination.params ? isRef(props.pagination.params) ? props.pagination.params.value : props.pagination.params : {};
|
const params = getActualValue<Paging['params']>(props.pagination.params, {});
|
||||||
const offsetMode = props.offsetMode ? isRef(props.offsetMode) ? props.offsetMode.value : props.offsetMode : false;
|
const offsetMode = getActualValue(props.pagination.offsetMode, false);
|
||||||
await misskeyApi<MisskeyEntity[]>(props.pagination.endpoint, {
|
await misskeyApi<MisskeyEntity[]>(props.pagination.endpoint, {
|
||||||
...params,
|
...params,
|
||||||
limit: SECOND_FETCH_LIMIT,
|
limit: SECOND_FETCH_LIMIT,
|
||||||
|
@ -304,8 +310,8 @@ const fetchMore = async (): Promise<void> => {
|
||||||
const fetchMoreAhead = async (): Promise<void> => {
|
const fetchMoreAhead = async (): Promise<void> => {
|
||||||
if (!more.value || fetching.value || moreFetching.value || items.value.size === 0) return;
|
if (!more.value || fetching.value || moreFetching.value || items.value.size === 0) return;
|
||||||
moreFetching.value = true;
|
moreFetching.value = true;
|
||||||
const params = props.pagination.params ? isRef(props.pagination.params) ? props.pagination.params.value : props.pagination.params : {};
|
const params = getActualValue<Paging['params']>(props.pagination.params, {});
|
||||||
const offsetMode = props.offsetMode ? isRef(props.offsetMode) ? props.offsetMode.value : props.offsetMode : false;
|
const offsetMode = getActualValue(props.pagination.offsetMode, false);
|
||||||
await misskeyApi<MisskeyEntity[]>(props.pagination.endpoint, {
|
await misskeyApi<MisskeyEntity[]>(props.pagination.endpoint, {
|
||||||
...params,
|
...params,
|
||||||
limit: SECOND_FETCH_LIMIT,
|
limit: SECOND_FETCH_LIMIT,
|
||||||
|
|
Loading…
Reference in a new issue