-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
search posts feature (only in the general context for now)
- Loading branch information
1 parent
1007afb
commit 8f29214
Showing
4 changed files
with
159 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<template> | ||
<div> | ||
<div class="input-group mb-3"> | ||
<input | ||
type="text" | ||
class="form-control text-center" | ||
placeholder="enter a search term" | ||
v-model="queryTerm" | ||
v-on:keyup.enter="search" | ||
> | ||
</div> | ||
|
||
<div class="text-center"> | ||
<button class="btn btn-primary mt-2 mb-4" :disabled="!queryTerm || waitingLoadPosts" @click="search"> | ||
Search | ||
</button> | ||
</div> | ||
|
||
<div v-if="orbisPosts"> | ||
<ChatPost | ||
v-for="post in orbisPosts" | ||
:key="post.stream_id" | ||
:post="post" | ||
:orbisContext="selectedContext" /> | ||
</div> | ||
|
||
<div class="d-flex justify-content-center mt-5 mb-4" v-if="searched && queryTerm && orbisPosts.length === 0 && !waitingLoadPosts"> | ||
<p>No posts. Try a different query.</p> | ||
</div> | ||
|
||
<div class="d-flex justify-content-center mb-3" v-if="waitingLoadPosts"> | ||
<span class="spinner-border spinner-border-lg" role="status" aria-hidden="true"></span> | ||
</div> | ||
|
||
<div class="d-grid gap-2 col-6 mx-auto mb-5" v-if="showLoadMore"> | ||
<button class="btn btn-primary" type="button" @click="search">Load more posts</button> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import ChatPost from "~/components/chat/ChatPost.vue"; | ||
import { useToast } from "vue-toastification/dist/index.mjs"; | ||
export default { | ||
name: "SearchPosts", | ||
data() { | ||
return { | ||
orbisPosts: [], | ||
pageCounter: 0, | ||
queryTerm: null, | ||
searched: false, | ||
selectedContext: this.$config.chatChannels.general, | ||
showLoadMore: false, | ||
waitingLoadPosts: false | ||
} | ||
}, | ||
components: { | ||
ChatPost | ||
}, | ||
methods: { | ||
async search() { | ||
this.waitingLoadPosts = true; | ||
let {data, error} = await this.$orbis.getPosts( | ||
{context: this.selectedContext, term: this.queryTerm}, | ||
this.pageCounter, | ||
this.$config.getPostsLimit, // posts limit | ||
false // ascending=true, descending=false | ||
); | ||
if (error) { | ||
this.toast("Error fetching posts from the Orbis/Ceramic node.", {type: "error"}); | ||
console.log(error); | ||
} | ||
if (data.length < this.$config.getPostsLimit) { | ||
this.showLoadMore = false; // hide Load More Posts button if there's less than getPostsLimit number of posts received | ||
} else if (data.length === this.$config.getPostsLimit) { | ||
this.showLoadMore = true; // show Load More Posts button if data length was full (getPostsLimit number of posts) | ||
} | ||
this.orbisPosts.push(...data); | ||
this.pageCounter++; | ||
this.waitingLoadPosts = false; | ||
this.searched = true; | ||
} | ||
}, | ||
setup() { | ||
const toast = useToast(); | ||
return { toast } | ||
}, | ||
watch: { | ||
// if queryTerm changes, clear the orbisPosts array | ||
queryTerm(newVal, oldVal) { | ||
if (newVal !== oldVal) { | ||
this.orbisPosts = []; | ||
this.pageCounter = 0; | ||
this.searched = false; | ||
} | ||
} | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<template> | ||
<Head> | ||
<Title>Search posts | {{ $config.projectMetadataTitle }}</Title> | ||
<Meta property="og:title" :content="'Search posts | ' + $config.projectMetadataTitle" /> | ||
</Head> | ||
|
||
<div class="scroll-500"> | ||
<div class="card border"> | ||
<div class="card-body mb-3"> | ||
<p class="fs-3"> | ||
<i class="bi bi-arrow-left-circle cursor-pointer" @click="$router.back()"></i> | ||
</p> | ||
|
||
<h3 class="mt-3">Search posts</h3> | ||
|
||
<div class="d-flex justify-content-center mt-5"> | ||
<div class="col-12 col-lg-8"> | ||
<SearchPosts /> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import SearchPosts from '~/components/search/SearchPosts.vue'; | ||
export default { | ||
name: 'SearchPostsPage', | ||
components: { | ||
SearchPosts, | ||
} | ||
} | ||
</script> |