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 enteredSearchTerm = ref('');
const hasProjects = computed(function() {
return props.user.projects && availableProjects.value.length > 0;
});
const availableProjects = computed(function() {
if (activeSearchTerm.value) {
return props.user.projects.filter(prj =>
prj.title.includes(activeSearchTerm)
prj.title.includes(activeSearchTerm.value)
);
}
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(() => {
if (val === enteredSearchTerm.value) {
activeSearchTerm.value = val;
if (newValue === enteredSearchTerm.value) {
activeSearchTerm.value = newValue;
}
}, 300);
});
watch(props.user, function() {
enteredSearchTerm.value = '';
});
function updateSearch(val) {
enteredSearchTerm.value = val;
}
function userSearch() {
enteredSearchTerm.value = '';
}
return {
enteredSearchTerm,
activeSearchTerm,
hasProjects,
availableProjects,
updateSearch,
userSearch
updateSearch
};
}
};