Skip to content

Commit

Permalink
Update search cast and crew queries
Browse files Browse the repository at this point in the history
  • Loading branch information
tushar-macrometa committed Jan 27, 2022
1 parent acb0a6e commit 6d96a9e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 28 deletions.
36 changes: 24 additions & 12 deletions api-service/src/utils/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ export const RESTQL = {
RETURN (
FOR cast, edge IN 1..2 OUTBOUND id asset_credit_edge
FILTER edge.type == "cast"
SORT cast.popularity DESC
LIMIT 4
RETURN cast
)
)
Expand All @@ -51,16 +49,24 @@ export const RESTQL = {
RETURN (
FOR crew, edge IN 1..2 OUTBOUND id asset_credit_edge
FILTER edge.type == "crew"
SORT crew.popularity DESC
LIMIT 4
RETURN crew
)
)
RETURN {
assets: UNIQUE(assets[0]),
cast: UNIQUE(FLATTEN(cast)),
crew: UNIQUE(FLATTEN(crew))
cast: (
FOR c IN UNIQUE(FLATTEN(cast))
SORT c.popularity DESC
LIMIT 23
RETURN c
),
crew: (
FOR c IN UNIQUE(FLATTEN(crew))
SORT c.popularity DESC
LIMIT 23
RETURN c
)
}`,
SEARCH_BY_CREDITS: `LET assets = (
LET credit_ids = (
Expand Down Expand Up @@ -91,8 +97,6 @@ export const RESTQL = {
RETURN (
FOR cast, edge IN 1..2 OUTBOUND id asset_credit_edge
FILTER edge.type == "cast"
SORT cast.popularity DESC
LIMIT 4
RETURN cast
)
)
Expand All @@ -102,15 +106,23 @@ export const RESTQL = {
RETURN (
FOR crew, edge IN 1..2 OUTBOUND id asset_credit_edge
FILTER edge.type == "crew"
SORT crew.popularity DESC
LIMIT 4
RETURN crew
)
)
RETURN {
assets: UNIQUE(assets),
cast: UNIQUE(FLATTEN(cast)),
crew: UNIQUE(FLATTEN(crew))
cast: (
FOR c IN UNIQUE(FLATTEN(cast))
SORT c.popularity DESC
LIMIT 23
RETURN c
),
crew: (
FOR c IN UNIQUE(FLATTEN(crew))
SORT c.popularity DESC
LIMIT 23
RETURN c
)
}`,
}

Expand Down
23 changes: 19 additions & 4 deletions react-app/src/pages/Search/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useDispatch, useSelector } from "react-redux"
import { selectSearchInputValue } from "../../redux/search/search.selectors"
import { changeSearchInputValue, fetchSearchResultsAsync } from "../../redux/search/search.actions"
import { FaCheck, FaTimes } from "react-icons/fa"
import { useState } from "react"
import { useEffect, useState } from "react"
import { FiChevronDown } from "react-icons/fi"
import { useRef } from "react"
import useOutsideClick from "../../hooks/useOutsideClick"
Expand All @@ -16,6 +16,9 @@ import SearchOperator from "./SearchOperator"
const Search = (searchResults) => {
const history = useHistory()
const dispatch = useDispatch()
const movieRef = useRef()
const castRef = useRef()
const crewRef = useRef()
const selectInputValue = useSelector(selectSearchInputValue)
const [searchHistory, setSearchHistory] = useState([])
const [searchHistoryExpanded, setSearchHistoryExpanded] = useState(false)
Expand All @@ -31,6 +34,18 @@ const Search = (searchResults) => {
transition: { duration: 0.8, ease: [0.04, 0.62, 0.23, 0.98] },
}

useEffect(() => {
if (results.assets.length && results.crew.length && results.cast.length) {
let scrollToTop = {
top: 0,
behavior: "smooth",
}
castRef.current.scrollTo(scrollToTop)
crewRef.current.scrollTo(scrollToTop)
movieRef.current.scrollTo(scrollToTop)
}
}, [JSON.stringify(results)])

useOutsideClick(searchHistoryRef, () => {
if (searchHistoryExpanded) setSearchHistoryExpanded(false)
})
Expand Down Expand Up @@ -215,7 +230,7 @@ const Search = (searchResults) => {
{results.assets && results.assets.length > 0 ? (
<>
<h3>Movie / TV</h3>
<motion.ul>
<motion.ul ref={movieRef}>
{results.assets.map((result, index) => (
<motion.li
key={index}
Expand Down Expand Up @@ -245,7 +260,7 @@ const Search = (searchResults) => {
{results.cast && results.cast.length > 0 ? (
<>
<h3>Cast</h3>
<motion.ul>
<motion.ul ref={castRef}>
{results.cast.map((result, index) => (
<motion.li
key={index}
Expand All @@ -271,7 +286,7 @@ const Search = (searchResults) => {
{results.crew && results.crew.length > 0 ? (
<>
<h3>Crew</h3>
<motion.ul>
<motion.ul ref={crewRef}>
{results.crew.map((result, index) => (
<motion.li
key={index}
Expand Down
36 changes: 24 additions & 12 deletions react-app/src/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ export const restql = {
RETURN (
FOR cast, edge IN 1..2 OUTBOUND id asset_credit_edge
FILTER edge.type == "cast"
SORT cast.popularity DESC
LIMIT 4
RETURN cast
)
)
Expand All @@ -68,16 +66,24 @@ export const restql = {
RETURN (
FOR crew, edge IN 1..2 OUTBOUND id asset_credit_edge
FILTER edge.type == "crew"
SORT crew.popularity DESC
LIMIT 4
RETURN crew
)
)
RETURN {
assets: UNIQUE(assets[0]),
cast: UNIQUE(FLATTEN(cast)),
crew: UNIQUE(FLATTEN(crew))
cast: (
FOR c IN UNIQUE(FLATTEN(cast))
SORT c.popularity DESC
LIMIT 23
RETURN c
),
crew: (
FOR c IN UNIQUE(FLATTEN(crew))
SORT c.popularity DESC
LIMIT 23
RETURN c
)
}`,
searchByCredits: `LET assets = (
LET credit_ids = (
Expand Down Expand Up @@ -108,8 +114,6 @@ export const restql = {
RETURN (
FOR cast, edge IN 1..2 OUTBOUND id asset_credit_edge
FILTER edge.type == "cast"
SORT cast.popularity DESC
LIMIT 4
RETURN cast
)
)
Expand All @@ -119,15 +123,23 @@ export const restql = {
RETURN (
FOR crew, edge IN 1..2 OUTBOUND id asset_credit_edge
FILTER edge.type == "crew"
SORT crew.popularity DESC
LIMIT 4
RETURN crew
)
)
RETURN {
assets: UNIQUE(assets),
cast: UNIQUE(FLATTEN(cast)),
crew: UNIQUE(FLATTEN(crew))
cast: (
FOR c IN UNIQUE(FLATTEN(cast))
SORT c.popularity DESC
LIMIT 23
RETURN c
),
crew: (
FOR c IN UNIQUE(FLATTEN(crew))
SORT c.popularity DESC
LIMIT 23
RETURN c
)
}`,
}

Expand Down

0 comments on commit 6d96a9e

Please sign in to comment.