Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SetContacts.vue « SetContacts « NewGroupConversation « LeftSidebar « components « src - github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bbb30898cafbe39a81f4b083ae0dfd5d86dd7038 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<!--
  - @copyright Copyright (c) 2019 Marco Ambrosini <marcoambrosini@pm.me>
  -
  - @author Marco Ambrosini <marcoambrosini@pm.me>
  -
  - @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="set-contacts">
		<!-- Search -->
		<div class="icon-search" />
		<input
			ref="setContacts"
			v-model="searchText"
			v-observe-visibility="visibilityChanged"
			class="set-contacts__input"
			type="text"
			:placeholder="t('spreed', 'Search participants')"
			@input="handleInput">
		<transition-group
			v-if="hasSelectedParticipants"
			name="zoom"
			tag="div"
			class="selected-participants">
			<ContactSelectionBubble
				v-for="participant in selectedParticipants"
				:key="participant.source + participant.id"
				:participant="participant" />
		</transition-group>
		<ParticipantSearchResults
			:add-on-click="false"
			:search-results="searchResults"
			:contacts-loading="contactsLoading"
			:no-results="noResults"
			:scrollable="true"
			:display-search-hint="displaySearchHint"
			:selectable="true"
			@clickSearchHint="focusInput" />
	</div>
</template>

<script>
import CancelableRequest from '../../../../utils/cancelableRequest'
import debounce from 'debounce'
import { showError } from '@nextcloud/dialogs'
import { searchPossibleConversations } from '../../../../services/conversationsService'
import ParticipantSearchResults from '../../../RightSidebar/Participants/ParticipantsSearchResults/ParticipantsSearchResults'
import ContactSelectionBubble from './ContactSelectionBubble/ContactSelectionBubble'

export default {
	name: 'SetContacts',
	components: {
		ParticipantSearchResults,
		ContactSelectionBubble,
	},

	props: {
		conversationName: {
			type: String,
			required: true,
		},
	},

	data() {
		return {
			searchText: '',
			searchResults: [],
			// The loading state is true when the component is initialised as we perform a search for 'contacts'
			// with an empty screen as search text.
			contactsLoading: true,
			noResults: false,
			cancelSearchPossibleConversations: () => {},
		}
	},

	computed: {
		selectedParticipants() {
			return this.$store.getters.selectedParticipants
		},
		hasSelectedParticipants() {
			return this.selectedParticipants.length !== 0
		},
		/**
		 * Search hint at the bottom of the participants list, displayed only if
		 * the user is not searching
		 *
		 * @return {boolean}
		 */
		displaySearchHint() {
			return !this.contactsLoading && this.searchText === ''
		},
	},

	async mounted() {
		// Focus the input field of the current component.
		this.focusInput()
		// Perform a search with an empty string
		await this.fetchSearchResults()
		// Once the contacts are fetched, remove the spinner.
		this.contactsLoading = false
	},

	beforeDestroy() {
		this.cancelSearchPossibleConversations()
		this.cancelSearchPossibleConversations = null
	},

	methods: {
		handleInput() {
			this.noResults = false
			this.contactsLoading = true
			this.searchResults = []
			this.debounceFetchSearchResults()
		},

		debounceFetchSearchResults: debounce(function() {
			this.fetchSearchResults()
		}, 250),

		async fetchSearchResults() {
			try {
				this.cancelSearchPossibleConversations('canceled')
				const { request, cancel } = CancelableRequest(searchPossibleConversations)
				this.cancelSearchPossibleConversations = cancel

				const response = await request({ searchText: this.searchText })

				this.searchResults = response?.data?.ocs?.data || []
				this.contactsLoading = false
				if (this.searchResults.length === 0) {
					this.noResults = true
				}
			} catch (exception) {
				if (CancelableRequest.isCancel(exception)) {
					return
				}
				console.error(exception)
				showError(t('spreed', 'An error occurred while performing the search'))
			}
		},
		visibilityChanged(isVisible) {
			if (isVisible) {
				// Focus the input field of the current component.
				this.focusInput()
			}
		},
		focusInput() {
			this.$refs.setContacts.focus()
		},
	},
}
</script>

<style lang="scss" scoped>
.set-contacts {
	position: relative;
	height: 100%;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	&__input {
		width: 100%;
		font-size: 16px;
		padding-left: 28px;
		line-height: 34px;
		box-shadow: 0 10px 5px var(--color-main-background);
		z-index: 1;
	}
	&__icon {
		margin-top: 40px;
	}
	&__hint {
		margin-top: 20px;
		text-align: center;
	}
}

.selected-participants {
	display: flex;
	flex-wrap: wrap;
	border-bottom: 1px solid var(--color-background-darker);
	padding: 4px 0;
	max-height: 97px;
	overflow-y: auto;
	flex: 0 240px;
	flex: 1 0 auto;
	align-content: flex-start;
}

.icon-search {
	position: absolute;
	top: 12px;
	left: 8px;
	z-index: 2;
}

.zoom-enter-active {
	animation: zoom-in var(--animation-quick);
}

.zoom-leave-active {
	animation: zoom-in var(--animation-quick) reverse;
	will-change: transform;
}

@keyframes zoom-in {
	0% {
		transform: scale(0);
	}
	100% {
		transform: scale(1);
	}
}

</style>