Selaa lähdekoodia

Filter pending videos search (#752)

* add mediaAvailability condition to SearchResults

* add thumbnail availability to condition

* add filtering through query
mikkio 3 vuotta sitten
vanhempi
commit
c0996edb3d

+ 2 - 0
src/api/queries/__generated__/baseTypes.generated.ts

@@ -344,6 +344,8 @@ export type QueryMembershipsArgs = {
 export type QuerySearchArgs = {
   limit?: Maybe<Scalars['Int']>
   text: Scalars['String']
+  whereVideo?: Maybe<VideoWhereInput>
+  whereChannel?: Maybe<ChannelWhereInput>
 }
 
 export type QueryVideoByUniqueInputArgs = {

+ 6 - 2
src/api/queries/__generated__/search.generated.tsx

@@ -7,6 +7,8 @@ import { VideoFieldsFragment, VideoFieldsFragmentDoc } from './videos.generated'
 
 export type SearchQueryVariables = Types.Exact<{
   text: Types.Scalars['String']
+  whereVideo?: Types.Maybe<Types.VideoWhereInput>
+  whereChannel?: Types.Maybe<Types.ChannelWhereInput>
 }>
 
 export type SearchQuery = {
@@ -18,8 +20,8 @@ export type SearchQuery = {
 }
 
 export const SearchDocument = gql`
-  query Search($text: String!) {
-    search(text: $text) {
+  query Search($text: String!, $whereVideo: VideoWhereInput, $whereChannel: ChannelWhereInput) {
+    search(text: $text, whereVideo: $whereVideo, whereChannel: $whereChannel) {
       item {
         ... on Video {
           ...VideoFields
@@ -47,6 +49,8 @@ export const SearchDocument = gql`
  * const { data, loading, error } = useSearchQuery({
  *   variables: {
  *      text: // value for 'text'
+ *      whereVideo: // value for 'whereVideo'
+ *      whereChannel: // value for 'whereChannel'
  *   },
  * });
  */

+ 2 - 2
src/api/queries/search.graphql

@@ -1,5 +1,5 @@
-query Search($text: String!) {
-  search(text: $text) {
+query Search($text: String!, $whereVideo: VideoWhereInput, $whereChannel: ChannelWhereInput) {
+  search(text: $text, whereVideo: $whereVideo, whereChannel: $whereChannel) {
     item {
       ... on Video {
         ...VideoFields

+ 1 - 1
src/api/schemas/extendedQueryNode.graphql

@@ -306,7 +306,7 @@ type Query {
   coverVideo: CoverVideo!
 
   # Free text search across videos and channels
-  search(limit: Int, text: String!): [SearchFTSOutput!]!
+  search(limit: Int, text: String!, whereVideo: VideoWhereInput, whereChannel: ChannelWhereInput): [SearchFTSOutput!]!
 }
 
 type Subscription {

+ 9 - 2
src/views/viewer/SearchOverlayView/SearchResults/SearchResults.tsx

@@ -2,7 +2,7 @@ import styled from '@emotion/styled'
 import React, { useState, useMemo } from 'react'
 
 import { useSearch } from '@/api/hooks'
-import { SearchQuery } from '@/api/queries'
+import { SearchQuery, AssetAvailability } from '@/api/queries'
 import { VideoGrid, PlaceholderVideoGrid, ChannelGrid, ViewWrapper } from '@/components'
 import { usePersonalData } from '@/hooks'
 import { Tabs } from '@/shared/components'
@@ -18,7 +18,14 @@ const tabs = ['all results', 'videos', 'channels']
 
 const SearchResults: React.FC<SearchResultsProps> = ({ query }) => {
   const [selectedIndex, setSelectedIndex] = useState(0)
-  const { data, loading, error } = useSearch({ text: query })
+  const { data, loading, error } = useSearch({
+    text: query,
+    whereVideo: {
+      mediaAvailability_eq: AssetAvailability.Accepted,
+      thumbnailPhotoAvailability_eq: AssetAvailability.Accepted,
+    },
+    whereChannel: {},
+  })
 
   const getChannelsAndVideos = (loading: boolean, data: SearchQuery['search'] | undefined) => {
     if (loading || !data) {