Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slot for no results added #72

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/components/InfiniteLoading.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts" setup>
import type { Props, Params, State, StateHandler } from "@root/types";
import { onMounted, ref, toRefs, onUnmounted, watch, nextTick } from "vue";
import { computed, onMounted, ref, toRefs, onUnmounted, watch, nextTick } from "vue";
import { startObserver, getParentEl, isVisible } from "@root/utils";
// @ts-ignore
import Spinner from "./Spinner.vue";
Expand Down Expand Up @@ -43,6 +43,7 @@ const stateHandler: StateHandler = {
state.value = "loading";
},
async loaded() {
params.firstload = false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regarding the documentation, firstload is used for a different scope.

This property is used to specify weither you want the component to handle first load or not

Create an internal variable to store it.

state.value = "loaded";
const parentEl = params.parentEl || document.documentElement;
await nextTick();
Expand Down Expand Up @@ -71,6 +72,12 @@ onMounted(async () => {
onUnmounted(() => {
observer?.disconnect();
});

const showNoMore = computed(() => state.value == "complete" && !params.firstload);

const showNoResults = computed(() => state.value == "complete" && params.firstload);

const showError = computed(() => state.value === "error");
</script>

<template>
Expand All @@ -80,10 +87,13 @@ onUnmounted(() => {
<Spinner />
</slot>
</div>
<slot v-if="state == 'complete'" name="complete">
<slot v-if="showNoMore" name="complete">
<span> {{ slots?.complete || "No more results!" }} </span>
</slot>
<slot v-if="state == 'error'" name="error" :retry="params.emit">
<slot v-if="showNoResults" name="noResults">
<span> {{ slots?.noResults || "No data found!" }} </span>
</slot>
<slot v-if="showError" name="error" :retry="params.emit">
<span class="state-error">
<span>{{ slots?.error || "Oops something went wrong!" }}</span>
<button class="retry" @click="params.emit">retry</button>
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface Params {

export interface Slots {
complete?: string;
noResults?: string;
error?: string;
}

Expand Down
Loading