Key highlights: - Written from scratch to cater specifically to privacy.sexy's needs and requirements. - The visual look mimics the previous component with minimal changes, but its internal code is completely rewritten. - Lays groundwork for future functionalities like the "expand all" button a flat view mode as discussed in #158. - Facilitates the transition to Vue 3 by omitting the Vue 2.0 dependent `liquour-tree` as part of #230. Improvements and features: - Caching for quicker node queries. - Gradual rendering of nodes that introduces a noticable boost in performance, particularly during search/filtering. - `TreeView` solely governs the check states of branch nodes. Changes: - Keyboard interactions now alter the background color to highlight the focused item. Previously, it was changing the color of the text. - Better state management with clear separation of concerns: - `TreeView` exclusively manages indeterminate states. - `TreeView` solely governs the check states of branch nodes. - Introduce transaction pattern to update state in batches to minimize amount of events handled. - Improve keyboard focus, style background instead of foreground. Use hover/touch color on keyboard focus. - `SelectableTree` has been removed. Instead, `TreeView` is now directly integrated with `ScriptsTree`. - `ScriptsTree` has been refactored to incorporate hooks for clearer code and separation of duties. - Adopt Vue-idiomatic bindings instead of keeping a reference of the tree component. - Simplify and change filter event management. - Abandon global styles in favor of class-scoped styles. - Use global mixins with descriptive names to clarify indended functionality.
185 lines
4.9 KiB
Vue
185 lines
4.9 KiB
Vue
<template>
|
|
<div class="scripts">
|
|
<div v-if="!isSearching">
|
|
<template v-if="currentView === ViewType.Cards">
|
|
<CardList />
|
|
</template>
|
|
<template v-else-if="currentView === ViewType.Tree">
|
|
<div class="tree">
|
|
<ScriptsTree />
|
|
</div>
|
|
</template>
|
|
</div>
|
|
<div v-else> <!-- Searching -->
|
|
<div class="search">
|
|
<div class="search__query">
|
|
<div>Searching for "{{ trimmedSearchQuery }}"</div>
|
|
<div
|
|
class="search__query__close-button"
|
|
v-on:click="clearSearchQuery()"
|
|
>
|
|
<font-awesome-icon :icon="['fas', 'times']" />
|
|
</div>
|
|
</div>
|
|
<div v-if="!searchHasMatches" class="search-no-matches">
|
|
<div>Sorry, no matches for "{{ trimmedSearchQuery }}" 😞</div>
|
|
<div>
|
|
Feel free to extend the scripts
|
|
<a :href="repositoryUrl" class="child github" target="_blank" rel="noopener noreferrer">here</a> ✨
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div v-if="searchHasMatches" class="tree tree--searching">
|
|
<ScriptsTree />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
import {
|
|
defineComponent, PropType, ref, computed,
|
|
inject,
|
|
} from 'vue';
|
|
import { InjectionKeys } from '@/presentation/injectionSymbols';
|
|
import ScriptsTree from '@/presentation/components/Scripts/View/Tree/ScriptsTree.vue';
|
|
import CardList from '@/presentation/components/Scripts/View/Cards/CardList.vue';
|
|
import { ViewType } from '@/presentation/components/Scripts/Menu/View/ViewType';
|
|
import { IReadOnlyUserFilter } from '@/application/Context/State/Filter/IUserFilter';
|
|
import { IFilterResult } from '@/application/Context/State/Filter/IFilterResult';
|
|
|
|
export default defineComponent({
|
|
components: {
|
|
ScriptsTree,
|
|
CardList,
|
|
},
|
|
props: {
|
|
currentView: {
|
|
type: Number as PropType<ViewType>,
|
|
required: true,
|
|
},
|
|
},
|
|
setup() {
|
|
const { modifyCurrentState, onStateChange } = inject(InjectionKeys.useCollectionState)();
|
|
const { events } = inject(InjectionKeys.useAutoUnsubscribedEvents)();
|
|
const { info } = inject(InjectionKeys.useApplication);
|
|
|
|
const repositoryUrl = computed<string>(() => info.repositoryWebUrl);
|
|
const searchQuery = ref<string | undefined>();
|
|
const isSearching = computed(() => Boolean(searchQuery.value));
|
|
const searchHasMatches = ref(false);
|
|
const trimmedSearchQuery = computed(() => {
|
|
const query = searchQuery.value;
|
|
const threshold = 30;
|
|
if (query.length <= threshold - 3) {
|
|
return query;
|
|
}
|
|
return `${query.substring(0, threshold)}...`;
|
|
});
|
|
|
|
onStateChange((newState) => {
|
|
updateFromInitialFilter(newState.filter.currentFilter);
|
|
events.unsubscribeAllAndRegister([
|
|
subscribeToFilterChanges(newState.filter),
|
|
]);
|
|
}, { immediate: true });
|
|
|
|
function clearSearchQuery() {
|
|
modifyCurrentState((state) => {
|
|
const { filter } = state;
|
|
filter.clearFilter();
|
|
});
|
|
}
|
|
|
|
function updateFromInitialFilter(filter?: IFilterResult) {
|
|
searchQuery.value = filter?.query;
|
|
searchHasMatches.value = filter?.hasAnyMatches();
|
|
}
|
|
|
|
function subscribeToFilterChanges(filter: IReadOnlyUserFilter) {
|
|
return filter.filterChanged.on((event) => {
|
|
event.visit({
|
|
onApply: (newFilter) => {
|
|
searchQuery.value = newFilter.query;
|
|
searchHasMatches.value = newFilter.hasAnyMatches();
|
|
},
|
|
onClear: () => {
|
|
searchQuery.value = undefined;
|
|
},
|
|
});
|
|
});
|
|
}
|
|
|
|
return {
|
|
repositoryUrl,
|
|
trimmedSearchQuery,
|
|
isSearching,
|
|
searchHasMatches,
|
|
clearSearchQuery,
|
|
ViewType,
|
|
};
|
|
},
|
|
});
|
|
</script>
|
|
|
|
<style scoped lang="scss">
|
|
@use "@/presentation/assets/styles/main" as *;
|
|
|
|
$margin-inner: 4px;
|
|
|
|
.scripts {
|
|
margin-top: $margin-inner;
|
|
@media screen and (min-width: $media-vertical-view-breakpoint) {
|
|
// so the current code is always visible
|
|
overflow: auto;
|
|
max-height: 70vh;
|
|
}
|
|
.tree {
|
|
padding-left: 3%;
|
|
padding-top: 15px;
|
|
padding-bottom: 15px;
|
|
&--searching {
|
|
background-color: $color-primary-darker;
|
|
padding-top: 0px;
|
|
}
|
|
}
|
|
}
|
|
|
|
.search {
|
|
display: flex;
|
|
flex-direction: column;
|
|
background-color: $color-primary-darker;
|
|
&__query {
|
|
display: flex;
|
|
justify-content: center;
|
|
flex-direction: row;
|
|
align-items: center;
|
|
margin-top: 1em;
|
|
color: $color-primary;
|
|
&__close-button {
|
|
@include clickable;
|
|
font-size: 1.25em;
|
|
margin-left: 0.25rem;
|
|
@include hover-or-touch {
|
|
color: $color-primary-dark;
|
|
}
|
|
}
|
|
}
|
|
&-no-matches {
|
|
display:flex;
|
|
flex-direction: column;
|
|
word-break:break-word;
|
|
color: $color-on-primary;
|
|
font-size: 1.5em;
|
|
padding:10px;
|
|
text-align:center;
|
|
> div {
|
|
padding-bottom:13px;
|
|
}
|
|
a {
|
|
color: $color-primary;
|
|
}
|
|
}
|
|
}
|
|
</style>
|