social/src/components/Search.vue

175 wiersze
4.3 KiB
Vue
Czysty Zwykły widok Historia

<!--
- @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
-
- @author Julius Härtl <jus@bitgrid.net>
-
- @license GNU AGPL version 3 or any later version
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-->
<template>
<div class="social__wrapper">
<div v-if="allResults.length < 1 && hashtags.length < 1" id="emptycontent" :class="{'icon-loading': loading || remoteLoading}">
<div v-if="!loading" class="icon-search" />
<h2 v-if="!loading">
{{ t('social', 'No results found') }}
</h2>
<p v-if="!loading">
{{ t('social', 'There were no results for your search:') }} {{ decodeURIComponent(term) }}
</p>
</div>
<div v-else>
<h3>{{ t('social', 'Searching for') }} {{ decodeURIComponent(term) }}</h3>
<UserEntry v-for="result in allResults" :key="result.id" :item="result" />
<div v-if="hashtags.length > 0">
<li v-for="tag in hashtags" :key="tag.hashtag" class="tag">
<router-link :to="{ name: 'tags', params: {tag: tag.hashtag } }">
<span>#{{ tag.hashtag }}</span>
<Trend :data="trendData(tag.trend)"
:gradient="['#17adff', '#0082c9']"
:smooth="true"
:width="150"
:height="44"
stroke-width="2" />
</router-link>
</li>
</div>
</div>
</div>
</template>
<script>
import UserEntry from './UserEntry.vue'
import axios from '@nextcloud/axios'
import Trend from 'vuetrend'
import { generateUrl } from '@nextcloud/router'
Use new Mastodon like API Revert "Revert "Merge pull request #1581 from nextcloud/artonge/feat/use_new_api"" This reverts commit c4eef0b2d476ffcf10cfc3a44ea426d3ec7587b4. Signed-off-by: Louis Chemineau <louis@chmn.me> Adapt views to new timeline api Signed-off-by: Louis Chemineau <louis@chmn.me> Add types Signed-off-by: Louis Chemineau <louis@chmn.me> Fix type errors Signed-off-by: Louis Chemineau <louis@chmn.me> Adapte front-end to mastodon data format + Add typing + Modernize code Signed-off-by: Louis Chemineau <louis@chmn.me> Use new API for media attachments + Split Composer.vue into tinier composent + Use blurhash value of attachments Signed-off-by: Louis Chemineau <louis@chmn.me> Fix media attachment rendering in post component Signed-off-by: Louis Chemineau <louis@chmn.me> Use square container to display statuses attachments Signed-off-by: Louis Chemineau <louis@chmn.me> Add typing to timeline.js And fix type errors Signed-off-by: Louis Chemineau <louis@chmn.me> Forward format to getStreamSelectSql for direct timeline Signed-off-by: Louis Chemineau <louis@chmn.me> Fix liked timeline Signed-off-by: Louis Chemineau <louis@chmn.me> Use new API for local and federated timelines Signed-off-by: Louis Chemineau <louis@chmn.me> Fix profile and avatar for local users Signed-off-by: Louis Chemineau <louis@chmn.me> Update babel config Signed-off-by: Louis Chemineau <louis@chmn.me> Improve typing in account.js Signed-off-by: Louis Chemineau <louis@chmn.me> Handle new notification format Signed-off-by: Louis Chemineau <louis@chmn.me> Fix follow button Signed-off-by: Louis Chemineau <louis@chmn.me> Fix condition of delete button for statuses Signed-off-by: Louis Chemineau <louis@chmn.me> Add relationship fetching Signed-off-by: Louis Chemineau <louis@chmn.me> Improve attachments viewer Signed-off-by: Louis Chemineau <louis@chmn.me> Correctly use twemoji Signed-off-by: Louis Chemineau <louis@chmn.me> Clean up composer Signed-off-by: Louis Chemineau <louis@chmn.me> Insert emoji on the last line instead of creating a new one Signed-off-by: Louis Chemineau <louis@chmn.me> Overall improvements in composer Signed-off-by: Louis Chemineau <louis@chmn.me> Clean up PreviewGridItem Signed-off-by: Louis Chemineau <louis@chmn.me> Fix fetching relationships Signed-off-by: Louis Chemineau <louis@chmn.me> Fix followers and following list Signed-off-by: Louis Chemineau <louis@chmn.me> Fix direct link to followers and following lists Signed-off-by: Louis Chemineau <louis@chmn.me> Fix notifications endpoint Signed-off-by: Louis Chemineau <louis@chmn.me> Handle different types of notifications Signed-off-by: Louis Chemineau <louis@chmn.me> Add formatted date as title for statuses Signed-off-by: Louis Chemineau <louis@chmn.me> Fix entryContent computed property Signed-off-by: Louis Chemineau <louis@chmn.me> Handle reblog Signed-off-by: Louis Chemineau <louis@chmn.me> Fix favourite type Signed-off-by: Louis Chemineau <louis@chmn.me> Load context of status for single post Signed-off-by: Louis Chemineau <louis@chmn.me> Use new format to set the uid in single post Signed-off-by: Louis Chemineau <louis@chmn.me> Fix display name property Signed-off-by: Louis Chemineau <louis@chmn.me> Hack to handle context of single post Signed-off-by: Louis Chemineau <louis@chmn.me> Use item id to fetch context Signed-off-by: Louis Chemineau <louis@chmn.me> Remove unsused variable Signed-off-by: Louis Chemineau <louis@chmn.me>
2023-01-19 16:18:11 +00:00
import { translate } from '@nextcloud/l10n'
export default {
name: 'Search',
components: {
UserEntry,
Trend,
},
props: {
term: {
type: String,
default: '',
},
},
data() {
return {
results: {},
loading: false,
remoteLoading: false,
match: null,
hashtags: [],
}
},
computed: {
Use new Mastodon like API Revert "Revert "Merge pull request #1581 from nextcloud/artonge/feat/use_new_api"" This reverts commit c4eef0b2d476ffcf10cfc3a44ea426d3ec7587b4. Signed-off-by: Louis Chemineau <louis@chmn.me> Adapt views to new timeline api Signed-off-by: Louis Chemineau <louis@chmn.me> Add types Signed-off-by: Louis Chemineau <louis@chmn.me> Fix type errors Signed-off-by: Louis Chemineau <louis@chmn.me> Adapte front-end to mastodon data format + Add typing + Modernize code Signed-off-by: Louis Chemineau <louis@chmn.me> Use new API for media attachments + Split Composer.vue into tinier composent + Use blurhash value of attachments Signed-off-by: Louis Chemineau <louis@chmn.me> Fix media attachment rendering in post component Signed-off-by: Louis Chemineau <louis@chmn.me> Use square container to display statuses attachments Signed-off-by: Louis Chemineau <louis@chmn.me> Add typing to timeline.js And fix type errors Signed-off-by: Louis Chemineau <louis@chmn.me> Forward format to getStreamSelectSql for direct timeline Signed-off-by: Louis Chemineau <louis@chmn.me> Fix liked timeline Signed-off-by: Louis Chemineau <louis@chmn.me> Use new API for local and federated timelines Signed-off-by: Louis Chemineau <louis@chmn.me> Fix profile and avatar for local users Signed-off-by: Louis Chemineau <louis@chmn.me> Update babel config Signed-off-by: Louis Chemineau <louis@chmn.me> Improve typing in account.js Signed-off-by: Louis Chemineau <louis@chmn.me> Handle new notification format Signed-off-by: Louis Chemineau <louis@chmn.me> Fix follow button Signed-off-by: Louis Chemineau <louis@chmn.me> Fix condition of delete button for statuses Signed-off-by: Louis Chemineau <louis@chmn.me> Add relationship fetching Signed-off-by: Louis Chemineau <louis@chmn.me> Improve attachments viewer Signed-off-by: Louis Chemineau <louis@chmn.me> Correctly use twemoji Signed-off-by: Louis Chemineau <louis@chmn.me> Clean up composer Signed-off-by: Louis Chemineau <louis@chmn.me> Insert emoji on the last line instead of creating a new one Signed-off-by: Louis Chemineau <louis@chmn.me> Overall improvements in composer Signed-off-by: Louis Chemineau <louis@chmn.me> Clean up PreviewGridItem Signed-off-by: Louis Chemineau <louis@chmn.me> Fix fetching relationships Signed-off-by: Louis Chemineau <louis@chmn.me> Fix followers and following list Signed-off-by: Louis Chemineau <louis@chmn.me> Fix direct link to followers and following lists Signed-off-by: Louis Chemineau <louis@chmn.me> Fix notifications endpoint Signed-off-by: Louis Chemineau <louis@chmn.me> Handle different types of notifications Signed-off-by: Louis Chemineau <louis@chmn.me> Add formatted date as title for statuses Signed-off-by: Louis Chemineau <louis@chmn.me> Fix entryContent computed property Signed-off-by: Louis Chemineau <louis@chmn.me> Handle reblog Signed-off-by: Louis Chemineau <louis@chmn.me> Fix favourite type Signed-off-by: Louis Chemineau <louis@chmn.me> Load context of status for single post Signed-off-by: Louis Chemineau <louis@chmn.me> Use new format to set the uid in single post Signed-off-by: Louis Chemineau <louis@chmn.me> Fix display name property Signed-off-by: Louis Chemineau <louis@chmn.me> Hack to handle context of single post Signed-off-by: Louis Chemineau <louis@chmn.me> Use item id to fetch context Signed-off-by: Louis Chemineau <louis@chmn.me> Remove unsused variable Signed-off-by: Louis Chemineau <louis@chmn.me>
2023-01-19 16:18:11 +00:00
/** @return {import('../types/Mastodon.js').Account[]} */
allResults() {
if (this.results.accounts) {
if (this.results.accounts.exact) {
return [this.results.accounts.exact]
}
return this.results.accounts.result
}
return []
},
},
watch: {
term(val) {
this.search(val)
},
},
beforeMount() {
this.search(this.term)
},
methods: {
trendData(trend) {
const data = [
Math.max(0, trend['10d'] - trend['3d']),
Math.max(0, trend['3d'] - trend['1d']),
Math.max(0, trend['1d'] - trend['12h']),
Math.max(0, trend['12h'] - trend['1h']),
Math.max(0, trend['1h']),
]
return data
},
search(val) {
if (this.loading) {
return
}
this.loading = true
this.searchQuery(val).then((response) => {
this.results = response.data.result
this.loading = false
if (this.results.accounts.exact !== null) {
this.$store.commit('addAccount', { actorId: this.results.accounts.exact.id, data: this.results.accounts.exact })
}
this.results.accounts.result.forEach((account) => {
this.$store.commit('addAccount', { actorId: account.id, data: account })
})
this.hashtags = this.results.hashtags.result
})
},
accountSearch(term) {
this.loading = true
return axios.get(generateUrl('apps/social/api/v1/global/accounts/search?search=' + term))
},
searchQuery(term) {
this.loading = true
return axios.get(generateUrl('apps/social/api/v1/search?search=' + term))
},
remoteSearch(term) {
return axios.get(generateUrl('apps/social/api/v1/global/account/info?account=' + term))
},
Use new Mastodon like API Revert "Revert "Merge pull request #1581 from nextcloud/artonge/feat/use_new_api"" This reverts commit c4eef0b2d476ffcf10cfc3a44ea426d3ec7587b4. Signed-off-by: Louis Chemineau <louis@chmn.me> Adapt views to new timeline api Signed-off-by: Louis Chemineau <louis@chmn.me> Add types Signed-off-by: Louis Chemineau <louis@chmn.me> Fix type errors Signed-off-by: Louis Chemineau <louis@chmn.me> Adapte front-end to mastodon data format + Add typing + Modernize code Signed-off-by: Louis Chemineau <louis@chmn.me> Use new API for media attachments + Split Composer.vue into tinier composent + Use blurhash value of attachments Signed-off-by: Louis Chemineau <louis@chmn.me> Fix media attachment rendering in post component Signed-off-by: Louis Chemineau <louis@chmn.me> Use square container to display statuses attachments Signed-off-by: Louis Chemineau <louis@chmn.me> Add typing to timeline.js And fix type errors Signed-off-by: Louis Chemineau <louis@chmn.me> Forward format to getStreamSelectSql for direct timeline Signed-off-by: Louis Chemineau <louis@chmn.me> Fix liked timeline Signed-off-by: Louis Chemineau <louis@chmn.me> Use new API for local and federated timelines Signed-off-by: Louis Chemineau <louis@chmn.me> Fix profile and avatar for local users Signed-off-by: Louis Chemineau <louis@chmn.me> Update babel config Signed-off-by: Louis Chemineau <louis@chmn.me> Improve typing in account.js Signed-off-by: Louis Chemineau <louis@chmn.me> Handle new notification format Signed-off-by: Louis Chemineau <louis@chmn.me> Fix follow button Signed-off-by: Louis Chemineau <louis@chmn.me> Fix condition of delete button for statuses Signed-off-by: Louis Chemineau <louis@chmn.me> Add relationship fetching Signed-off-by: Louis Chemineau <louis@chmn.me> Improve attachments viewer Signed-off-by: Louis Chemineau <louis@chmn.me> Correctly use twemoji Signed-off-by: Louis Chemineau <louis@chmn.me> Clean up composer Signed-off-by: Louis Chemineau <louis@chmn.me> Insert emoji on the last line instead of creating a new one Signed-off-by: Louis Chemineau <louis@chmn.me> Overall improvements in composer Signed-off-by: Louis Chemineau <louis@chmn.me> Clean up PreviewGridItem Signed-off-by: Louis Chemineau <louis@chmn.me> Fix fetching relationships Signed-off-by: Louis Chemineau <louis@chmn.me> Fix followers and following list Signed-off-by: Louis Chemineau <louis@chmn.me> Fix direct link to followers and following lists Signed-off-by: Louis Chemineau <louis@chmn.me> Fix notifications endpoint Signed-off-by: Louis Chemineau <louis@chmn.me> Handle different types of notifications Signed-off-by: Louis Chemineau <louis@chmn.me> Add formatted date as title for statuses Signed-off-by: Louis Chemineau <louis@chmn.me> Fix entryContent computed property Signed-off-by: Louis Chemineau <louis@chmn.me> Handle reblog Signed-off-by: Louis Chemineau <louis@chmn.me> Fix favourite type Signed-off-by: Louis Chemineau <louis@chmn.me> Load context of status for single post Signed-off-by: Louis Chemineau <louis@chmn.me> Use new format to set the uid in single post Signed-off-by: Louis Chemineau <louis@chmn.me> Fix display name property Signed-off-by: Louis Chemineau <louis@chmn.me> Hack to handle context of single post Signed-off-by: Louis Chemineau <louis@chmn.me> Use item id to fetch context Signed-off-by: Louis Chemineau <louis@chmn.me> Remove unsused variable Signed-off-by: Louis Chemineau <louis@chmn.me>
2023-01-19 16:18:11 +00:00
t: translate,
},
}
</script>
<style scoped lang="scss">
.user-entry {
padding: 0;
}
h3 {
margin-top: -3px;
margin-left: 47px;
}
.tag {
list-style-type: none;
margin: 0;
padding: 0;
border-bottom: 1px solid var(--color-background-dark);
a {
display: flex;
span {
display: inline-block;
padding: 12px;
font-weight: 300;
flex-grow: 1;
}
}
}
</style>