Skip to content

Commit

Permalink
refactor: remove next queries from related prompt tag
Browse files Browse the repository at this point in the history
  • Loading branch information
victorcg88 committed Dec 9, 2024
1 parent b1ddd35 commit bbabdec
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 57 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/components/related-prompts/custom-related-prompts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
</i18n-t>

<div class="x-flex x-flex-col">
<RelatedPromptsTagList class="x-my-24" />
<RelatedPromptsTagList class="x-mt-24" />
<CustomQueryPreview
v-if="selectedPrompt !== -1"
:key="queriesPreviewInfo.length"
class="x-rounded-[12px] x-bg-neutral-10 x-px-16"
class="x-rounded-b-[12px] x-bg-neutral-10 x-px-16"
:queries-preview-info="queriesPreviewInfo"
></CustomQueryPreview>
</div>
Expand Down
57 changes: 5 additions & 52 deletions src/components/related-prompts/related-prompts-tag-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
v-for="(suggestion, index) in relatedPrompts"
:key="index"
:style="{ animationDelay: `${index * 0.4 + 0.05}s` }"
class="x-text-neutral-80 x-flex x-h-[112px] x-flex-col x-rounded-[12px] x-bg-neutral-10 x-text-md x-font-[400] x-transition-all x-duration-500 x-staggered-initial"
class="x-text-neutral-80 x-flex x-flex-col x-rounded-[12px] x-bg-neutral-10 x-text-md x-font-[400] x-transition-all x-duration-500 x-staggered-initial"
:class="[
{ 'x-staggered-animation': isVisible },
{ 'x-hidden': shouldHideButton(index) },
isSelected(index) ? 'x-w-full' : 'x-w-[204px] desktop:x-w-[303px]',
isSelected(index)
? 'x-w-full x-rounded-b-none'
: 'x-h-[112px] x-w-[204px] desktop:x-w-[303px]',
]"
data-test="related-prompt-item"
>
Expand All @@ -40,38 +42,11 @@
{{ suggestion.suggestionText }}
</span>
</div>
<div class="x-mr-8 x-mt-8">
<div :class="{ 'x-mr-8 x-mt-8': !isSelected(index) }">
<CrossTinyIcon v-if="isSelected(index)" class="x-icon-lg" />
<PlusIcon v-else class="x-icon-neutral-80 x-icon-lg" />
</div>
</button>

<!-- Next queries -->
<div
v-if="isSelected(index)"
class="x-no-scrollbar x-mt-8 x-flex x-w-full x-gap-12 x-overflow-y-hidden x-overflow-x-scroll x-px-16"
>
<button
v-for="(query, queryIndex) in suggestion.nextQueries"
:key="query"
:style="{ animationDelay: `${queryIndex * 0.3}s` }"
class="x-tag-outlined x-flex x-h-[40px] x-items-center x-justify-center x-gap-4 x-rounded-full x-border-1 x-px-12 x-staggered-initial x-staggered-animation"
:class="[
{ 'x-hidden': shouldHideButton(queryIndex) },
isQuerySelected(queryIndex) ? 'x-bg-neutral-25' : 'x-bg-neutral-0',
]"
@click="toggleQuery(queryIndex)"
>
<span
class="x-whitespace-nowrap x-text-sm"
:class="[isQuerySelected(queryIndex) ? ' x-text-neutral-90' : 'x-text-neutral-75']"
>
{{ query }}
</span>
<CrossTinyIcon v-if="isQuerySelected(queryIndex)" class="x-text-16 x-h-20" />
<PlusIcon v-else class="x-text-16 x-h-20" />
</button>
</div>
</div>
</div>
</CustomSlidingPanel>
Expand All @@ -96,7 +71,6 @@ export default defineComponent({
const isVisible = ref(false)
const selectedIndex = ref<number>(-1)
const selectedQuery = ref<number>(-1)
const observer = new IntersectionObserver(([entry]) => {
isVisible.value = entry.isIntersecting
Expand All @@ -116,51 +90,30 @@ export default defineComponent({
} else {
selectedIndex.value = index
}
selectedQuery.value = -1
x.emit('UserSelectedARelatedPrompt', selectedIndex.value)
x.emit('UserSelectedARelatedPromptQuery', selectedQuery.value)
}
const isSelected = (index: number): boolean => selectedIndex.value === index
const toggleQuery = (queryIndex: number): void => {
if (selectedQuery.value === queryIndex) {
selectedQuery.value = -1
} else {
selectedQuery.value = queryIndex
}
x.emit('UserSelectedARelatedPromptQuery', selectedQuery.value)
}
const isQuerySelected = (queryIndex: number): boolean => selectedQuery.value === queryIndex
const shouldHideButton = (index: number): boolean =>
selectedIndex.value !== -1 && selectedIndex.value !== index
const shouldHideQuery = (queryIndex: number): boolean =>
selectedQuery.value !== -1 && selectedQuery.value !== queryIndex
x.on('UserAcceptedAQueryPreview', false).subscribe(() => {
toggleSuggestion(-1)
toggleQuery(-1)
})
x.on('SearchRequestChanged', false).subscribe(() => {
toggleSuggestion(-1)
toggleQuery(-1)
})
return {
isQuerySelected,
isSelected,
isTouchable,
isVisible,
relatedPrompts,
selectedIndex,
shouldHideButton,
shouldHideQuery,
slidingPanelContent,
toggleQuery,
toggleSuggestion,
}
},
Expand Down
4 changes: 2 additions & 2 deletions src/components/search/results/results.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
</MainScrollItem>
</template>
<template #related-prompts-group>
<RelatedPromptsTagList v-if="!isLowResult" class="x-my-24" />
<RelatedPromptsTagList v-if="!isLowResult" class="-x-mb-1 x-mt-24 desktop:x-mt-0" />
<CustomQueryPreview
v-if="selectedPrompt !== -1"
:key="queriesPreviewInfo.length"
class="x-rounded-[12px] x-bg-neutral-10 x-px-8 desktop:x-px-16"
class="x-rounded-b-[12px] x-bg-neutral-10 x-px-8 desktop:x-px-16"
:queries-preview-info="queriesPreviewInfo"
></CustomQueryPreview>
</template>
Expand Down

0 comments on commit bbabdec

Please sign in to comment.