migrate the ProjectsList according to the solution

This commit is contained in:
Andreas Zweili 2021-09-04 16:44:16 +02:00
parent 3f0ae4d413
commit 2a10218809
1 changed files with 12 additions and 13 deletions

View File

@ -33,41 +33,40 @@ export default {
const activeSearchTerm = ref(''); const activeSearchTerm = ref('');
const enteredSearchTerm = ref(''); const enteredSearchTerm = ref('');
const hasProjects = computed(function() {
return props.user.projects && availableProjects.value.length > 0;
});
const availableProjects = computed(function() { const availableProjects = computed(function() {
if (activeSearchTerm.value) { if (activeSearchTerm.value) {
return props.user.projects.filter(prj => return props.user.projects.filter(prj =>
prj.title.includes(activeSearchTerm) prj.title.includes(activeSearchTerm.value)
); );
} }
return props.user.projects; return props.user.projects;
}); });
watch(enteredSearchTerm, function(val) { const hasProjects = computed(function() {
return props.user.projects && availableProjects.value.length > 0;
});
watch(enteredSearchTerm, function(newValue) {
setTimeout(() => { setTimeout(() => {
if (val === enteredSearchTerm.value) { if (newValue === enteredSearchTerm.value) {
activeSearchTerm.value = val; activeSearchTerm.value = newValue;
} }
}, 300); }, 300);
}); });
watch(props.user, function() {
enteredSearchTerm.value = '';
});
function updateSearch(val) { function updateSearch(val) {
enteredSearchTerm.value = val; enteredSearchTerm.value = val;
} }
function userSearch() {
enteredSearchTerm.value = '';
}
return { return {
enteredSearchTerm, enteredSearchTerm,
activeSearchTerm, activeSearchTerm,
hasProjects, hasProjects,
availableProjects, availableProjects,
updateSearch, updateSearch
userSearch
}; };
} }
}; };