Skip to content

Commit

Permalink
Add sensitivity toggles in filter sidebar and modal (#2672)
Browse files Browse the repository at this point in the history
Co-authored-by: Zack Krida <[email protected]>
  • Loading branch information
dhruvkb and zackkrida authored Jul 19, 2023
1 parent c7b7613 commit 80af08e
Show file tree
Hide file tree
Showing 11 changed files with 183 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<div v-show="audio.thumbnail && isOk" class="thumbnail absolute inset-0">
<img
ref="imgEl"
class="h-full w-full overflow-clip object-cover object-center"
class="h-full w-full overflow-clip object-cover object-center duration-200 motion-safe:transition-[filter,transform]"
:class="{ 'scale-150 blur-image': shouldBlur }"
:src="audio.thumbnail"
:alt="helpText"
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/VCheckbox/VCheckbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default defineComponent({
setup(props, { emit }) {
const localCheckedState = ref(props.checked || false)
const labelClasses = computed(() =>
props.disabled ? "text-dark-charcoal-70" : "text-dark-charcoal"
props.disabled ? "text-dark-charcoal-40" : "text-dark-charcoal"
)
const inputAttrs = computed<CheckboxAttrs>(() => {
const attrs: CheckboxAttrs = {
Expand Down
4 changes: 0 additions & 4 deletions frontend/src/components/VFilters/VSearchGridFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import { watchDebounced } from "@vueuse/core"
import { useSearchStore } from "~/stores/search"
import { areQueriesEqual, ApiQueryParams } from "~/utils/search-query-transform"
import type { NonMatureFilterCategory } from "~/constants/filters"
import { defineEvent } from "~/types/emits"
import { useI18n } from "~/composables/use-i18n"
import { useAnalytics } from "~/composables/use-analytics"
Expand Down Expand Up @@ -74,9 +73,6 @@ export default defineComponent({
default: true,
},
},
emits: {
close: defineEvent(),
},
setup() {
const searchStore = useSearchStore()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@
@select="$emit('select', $event)"
/>
</VTabPanel>
<VTabPanel v-if="showFilters" id="filters">
<!-- Horizontal padding removed to display divider. -->
<VTabPanel v-if="showFilters" id="filters" class="px-0">
<VSearchGridFilter
class="px-6"
:show-filter-header="false"
:change-tab-order="false"
/>
<VSafeBrowsing
v-if="isSensitiveContentEnabled"
class="border-t border-dark-charcoal-20 px-6 pt-6"
/>
</VTabPanel>
</VTabs>
<footer
Expand All @@ -77,6 +83,7 @@
import { computed, defineComponent, PropType, ref } from "vue"
import { useSearchStore } from "~/stores/search"
import { useFeatureFlagStore } from "~/stores/feature-flag"
import useSearchType from "~/composables/use-search-type"
Expand All @@ -92,12 +99,14 @@ import VShowResultsButton from "~/components/VHeader/VHeaderMobile/VShowResultsB
import VTab from "~/components/VTabs/VTab.vue"
import VTabPanel from "~/components/VTabs/VTabPanel.vue"
import VTabs from "~/components/VTabs/VTabs.vue"
import VSafeBrowsing from "~/components/VSafeBrowsing/VSafeBrowsing.vue"
type ContentSettingsTab = "content-settings" | "filters"
export default defineComponent({
name: "VContentSettingsModalContent",
components: {
VSafeBrowsing,
VCloseButton,
VIcon,
VModalContent,
Expand Down Expand Up @@ -158,7 +167,14 @@ export default defineComponent({
searchStore.clearFilters()
}
const featureStore = useFeatureFlagStore()
const isSensitiveContentEnabled = computed(() =>
featureStore.isOn("sensitive_content")
)
return {
isSensitiveContentEnabled,
searchType,
selectedTab,
Expand Down
110 changes: 110 additions & 0 deletions frontend/src/components/VSafeBrowsing/VSafeBrowsing.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<template>
<section id="safe-browsing" aria-labelledby="safe-browsing-heading">
<header class="relative mb-6 flex items-center justify-between">
<h4 id="safe-browsing-heading" class="caption-bold uppercase">
{{ $t("filters.safeBrowsing.title") }}
</h4>
</header>
<i18n tag="p" path="filters.safeBrowsing.desc" class="label-regular">
<template #sensitive>
<VLink :href="sensitivityPath">{{
$t("filters.safeBrowsing.sensitive")
}}</VLink>
</template>
</i18n>
<form class="safe-browsing-form">
<fieldset class="mb-10 mt-8 flex flex-col gap-8">
<div v-for="toggle in toggles" :key="toggle.name">
<VCheckbox
:id="toggle.name"
class="flex-row-reverse justify-between"
:value="toggle.name"
:checked="toggle.state.value"
:disabled="isDisabled(toggle.name)"
is-switch
@change="toggle.switchFn"
>
<span class="label-bold">{{
$t(`filters.safeBrowsing.toggles.${toggle.name}.title`)
}}</span>
</VCheckbox>
<p
class="label-regular mt-2"
:class="{ 'text-dark-charcoal-40': isDisabled(toggle.name) }"
>
{{ $t(`filters.safeBrowsing.toggles.${toggle.name}.desc`) }}
</p>
</div>
</fieldset>
</form>
</section>
</template>

<script lang="ts">
import { computed, defineComponent } from "vue"
import { useContext } from "@nuxtjs/composition-api"
import { useFeatureFlagStore } from "~/stores/feature-flag"
import { useUiStore } from "~/stores/ui"
import { ON, OFF } from "~/constants/feature-flag"
import VCheckbox from "~/components/VCheckbox/VCheckbox.vue"
import VLink from "~/components/VLink.vue"
/**
* Contains toggles to determine the users preferences towards fetching results
* that may contain sensitive content and subsequently blurring them to prevent
* accidental exposure or showing them directly.
*/
export default defineComponent({
name: "VSafeBrowsing",
components: { VCheckbox, VLink },
setup() {
const { app } = useContext()
const sensitivityPath = computed(() => app.localePath("/about")) // TODO: Issue#2550
const featureFlagStore = useFeatureFlagStore()
let fetchSensitive = computed(() =>
featureFlagStore.isOn("fetch_sensitive")
)
let setFetchSensitive = ({ checked }: { checked: boolean }) => {
featureFlagStore.toggleFeature("fetch_sensitive", checked ? ON : OFF)
if (!checked) {
// If sensitive content is not fetched, there is nothing to blur/unblur.
// In this case, we reset blurring to its default value.
setBlurSensitive({ checked: true })
}
}
const uiStore = useUiStore()
let blurSensitive = computed(() => uiStore.shouldBlurSensitive)
let setBlurSensitive = ({ checked }: { checked: boolean }) => {
uiStore.shouldBlurSensitive = checked
}
const toggles = [
{
name: "fetchSensitive",
state: fetchSensitive,
switchFn: setFetchSensitive,
},
{
name: "blurSensitive",
state: blurSensitive,
switchFn: setBlurSensitive,
},
]
const isDisabled = (name: string) =>
name === "blurSensitive" && !fetchSensitive.value
return {
sensitivityPath,
toggles,
isDisabled,
}
},
})
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Canvas, Description, Meta, Story } from "@storybook/addon-docs"

import VSafeBrowsing from "~/components/VSafeBrowsing/VSafeBrowsing.vue"

<Meta title="Components/VSafeBrowsing" component={VSafeBrowsing} />

export const Template = (args) => ({
template: `<VSafeBrowsing v-bind="args" />`,
components: { VSafeBrowsing },
setup() {
return { args }
},
})

# VSafeBrowsing

<Description of={VSafeBrowsing} />

<Canvas>
<Story
name="Default"
parameters={{
viewport: { defaultViewport: "xs" }, // because it is present in the sidebar
}}
>
{Template.bind({})}
</Story>
</Canvas>
2 changes: 1 addition & 1 deletion frontend/src/components/VSearchResultsGrid/VImageCell.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<img
ref="img"
loading="lazy"
class="block w-full rounded-sm object-cover"
class="block w-full rounded-sm object-cover duration-200 motion-safe:transition-[filter,transform]"
:class="[
isSquare ? 'h-full' : 'margin-auto',
{ 'scale-150 blur-image': shouldBlur },
Expand Down
17 changes: 10 additions & 7 deletions frontend/src/layouts/search-layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
v-if="isSidebarVisible"
class="sidebar end-0 z-10 h-full overflow-y-auto border-s border-dark-charcoal-20 bg-dark-charcoal-06"
>
<VSearchGridFilter class="px-10 pb-10 pt-8" @close="closeSidebar" />
<VSearchGridFilter class="px-10 py-8" />
<VSafeBrowsing
v-if="isSensitiveContentEnabled"
class="border-t border-dark-charcoal-20 px-10 py-8"
/>
</aside>

<div
Expand Down Expand Up @@ -100,6 +104,9 @@ export default defineComponent({
onMounted(() => {
featureStore.initFromSession()
})
const isSensitiveContentEnabled = computed(() =>
featureStore.isOn("sensitive_content")
)
const { updateBreakpoint } = useLayout()
Expand All @@ -126,10 +133,6 @@ export default defineComponent({
isDesktopLayout.value
)
const closeSidebar = () => {
uiStore.setFiltersState(false)
}
const isHeaderScrolled = ref(false)
const showScrollButton = ref(false)
Expand Down Expand Up @@ -161,6 +164,8 @@ export default defineComponent({
)
return {
isSensitiveContentEnabled,
mainPageRef,
headerRef,
Expand All @@ -170,8 +175,6 @@ export default defineComponent({
breakpoint,
headerBorder,
closeSidebar,
}
},
head() {
Expand Down
15 changes: 15 additions & 0 deletions frontend/src/locales/scripts/en.json5
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,21 @@
title: "Search Settings",
enable: "Enable Mature Content",
},
safeBrowsing: {
title: "Safe Browsing",
desc: "Content marked as {sensitive} is not shown by default.",
sensitive: "sensitive",
toggles: {
fetchSensitive: {
title: "Sensitive results",
desc: "Show results marked as sensitive in the results area.",
},
blurSensitive: {
title: "Blur content",
desc: "Blur images and texts to prevent seeing sensitive material.",
},
},
},
lengths: {
title: "Duration",
shortest: "< 30 sec",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 80af08e

Please sign in to comment.