@@ -11,7 +11,7 @@ import {Profile} from 'common/profiles/profile'
1111import { Row as rowFor } from 'common/supabase/utils'
1212import { User } from 'common/user'
1313import { shortenNumber } from 'common/util/format'
14- import { keyBy , partition , sortBy } from 'lodash'
14+ import { keyBy , sortBy } from 'lodash'
1515import { PinIcon } from 'lucide-react'
1616import { useCallback , useEffect , useMemo , useState } from 'react'
1717import toast from 'react-hot-toast'
@@ -31,15 +31,11 @@ import {Linkify} from 'web/components/widgets/linkify'
3131import { Pagination } from 'web/components/widgets/pagination'
3232import { Tooltip } from 'web/components/widgets/tooltip'
3333import { shortenName } from 'web/components/widgets/user-link'
34- import { useIsLooking } from 'web/hooks/use-is-looking'
3534import { usePersistentInMemoryState } from 'web/hooks/use-persistent-in-memory-state'
3635import { usePinnedQuestionIds } from 'web/hooks/use-pinned-question-ids'
3736import { useProfile } from 'web/hooks/use-profile'
3837import { useCompatibleProfiles } from 'web/hooks/use-profiles'
39- import {
40- useCompatibilityQuestionsWithAnswerCount ,
41- useUserCompatibilityAnswers ,
42- } from 'web/hooks/use-questions'
38+ import { useCompatibilityQuestionGroups , useUserCompatibilityAnswers } from 'web/hooks/use-questions'
4339import { useUser } from 'web/hooks/use-user'
4440import { useT } from 'web/lib/locale'
4541import { db } from 'web/lib/supabase/db'
@@ -65,29 +61,6 @@ import {PinQuestionButton} from './pin-question-button'
6561const NUM_QUESTIONS_TO_SHOW = 8
6662const NUM_PINNED_QUESTIONS_TO_SHOW = 4
6763
68- export function separateQuestionsArray (
69- questions : QuestionWithStats [ ] ,
70- skippedAnswerQuestionIds : Set < number > ,
71- answeredQuestionIds : Set < number > ,
72- ) {
73- debug ( 'Refreshing questions array' )
74- const skippedQuestions : QuestionWithStats [ ] = [ ]
75- const answeredQuestions : QuestionWithStats [ ] = [ ]
76- const otherQuestions : QuestionWithStats [ ] = [ ]
77-
78- questions . forEach ( ( q ) => {
79- if ( skippedAnswerQuestionIds . has ( q . id ) ) {
80- skippedQuestions . push ( q )
81- } else if ( answeredQuestionIds . has ( q . id ) ) {
82- answeredQuestions . push ( q )
83- } else {
84- otherQuestions . push ( q )
85- }
86- } )
87-
88- return { skippedQuestions, answeredQuestions, otherQuestions}
89- }
90-
9164export function CompatibilityQuestionsDisplay ( props : {
9265 isCurrentUser : boolean
9366 user : User
@@ -106,36 +79,24 @@ export function CompatibilityQuestionsDisplay(props: {
10679
10780 const { pinnedQuestionIds, refreshPinnedQuestionIds} = usePinnedQuestionIds ( )
10881
109- const { refreshCompatibilityQuestions, compatibilityQuestions} =
110- useCompatibilityQuestionsWithAnswerCount ( )
111-
112- const { refreshCompatibilityAnswers, compatibilityAnswers} = useUserCompatibilityAnswers ( user . id )
113-
114- const { answers, skippedQuestions, answeredQuestions, otherQuestions} = useMemo ( ( ) => {
115- debug ( 'Refreshing questions' )
116- const [ skippedAnswers , answers ] = partition (
117- compatibilityAnswers ,
118- ( answer ) => answer . importance == - 1 ,
119- )
120- const answeredQuestionIds = new Set ( answers . map ( ( answer ) => answer . question_id ) )
121- const skippedAnswerQuestionIds = new Set ( skippedAnswers . map ( ( answer ) => answer . question_id ) )
122- const { skippedQuestions, answeredQuestions, otherQuestions} = separateQuestionsArray (
123- compatibilityQuestions ,
124- skippedAnswerQuestionIds ,
125- answeredQuestionIds ,
126- )
127- return { answers, skippedQuestions, answeredQuestions, otherQuestions}
128- } , [ compatibilityAnswers , compatibilityQuestions ] )
82+ const {
83+ answers,
84+ skippedQuestions,
85+ answeredQuestions,
86+ otherQuestions,
87+ compatibilityQuestions,
88+ refreshCompatibilityAnswers,
89+ refreshCompatibilityQuestions,
90+ } = useCompatibilityQuestionGroups ( user . id )
12991
13092 const refreshCompatibilityAll = useCallback ( ( ) => {
13193 refreshCompatibilityAnswers ( )
13294 refreshCompatibilityQuestions ( )
13395 refreshPinnedQuestionIds ( )
13496 } , [ refreshCompatibilityAnswers , refreshCompatibilityQuestions , refreshPinnedQuestionIds ] )
13597
136- const isLooking = useIsLooking ( )
13798 const [ sort , setSort ] = usePersistentInMemoryState < CompatibilitySort > (
138- ! isLooking && ! fromProfilePage ? 'their_important ' : 'your_important ' ,
99+ isCurrentUser ? 'your_important ' : 'their_important ' ,
139100 `compatibility-sort-${ user . id } ` ,
140101 )
141102 const [ searchTerm , setSearchTerm ] = useState ( '' )
@@ -241,40 +202,42 @@ export function CompatibilityQuestionsDisplay(props: {
241202 ) }
242203 < Row className = "flex-wrap items-center justify-between gap-x-6 gap-y-4" >
243204 { answeredQuestions . length > 0 && (
244- < div className = "relative mt-3 w-full max-w-[50%] xl:max-w-[400px]" >
245- { /*<input*/ }
246- { /* type="text"*/ }
247- { /* placeholder={t('answers.search_placeholder', 'Search prompts...')}*/ }
248- { /* value={searchTerm}*/ }
249- { /* onChange={(e) => {*/ }
250- { /* setSearchTerm(e.target.value)*/ }
251- { /* setPage(0)*/ }
252- { /* }}*/ }
253- { /* className="h-8 pl-7 pr-2 text-sm border border-ink-300 rounded-xl bg-canvas-50 focus:outline-none focus:ring-1 focus:ring-primary-500 w-48 transition-all"*/ }
254- { /*/>*/ }
255- < Input
256- value = { searchTerm }
257- placeholder = { t ( 'answers.search_placeholder' , 'Search prompts...' ) }
258- className = { 'w-full' }
259- onChange = { ( e : React . ChangeEvent < HTMLInputElement > ) => {
260- setSearchTerm ( e . target . value )
261- } }
262- searchIcon
205+ < >
206+ < div className = "relative mt-3 w-full max-w-[50%] xl:max-w-[400px]" >
207+ { /*<input*/ }
208+ { /* type="text"*/ }
209+ { /* placeholder={t('answers.search_placeholder', 'Search prompts...')}*/ }
210+ { /* value={searchTerm}*/ }
211+ { /* onChange={(e) => {*/ }
212+ { /* setSearchTerm(e.target.value)*/ }
213+ { /* setPage(0)*/ }
214+ { /* }}*/ }
215+ { /* className="h-8 pl-7 pr-2 text-sm border border-ink-300 rounded-xl bg-canvas-50 focus:outline-none focus:ring-1 focus:ring-primary-500 w-48 transition-all"*/ }
216+ { /*/>*/ }
217+ < Input
218+ value = { searchTerm }
219+ placeholder = { t ( 'answers.search_placeholder' , 'Search prompts...' ) }
220+ className = { 'w-full' }
221+ onChange = { ( e : React . ChangeEvent < HTMLInputElement > ) => {
222+ setSearchTerm ( e . target . value )
223+ } }
224+ searchIcon
225+ />
226+ </ div >
227+ < CompatibilitySortWidget
228+ className = "text-sm sm:flex mt-4"
229+ sort = { sort }
230+ setSort = { setSort }
231+ user = { user }
232+ profile = { profile }
263233 />
264- </ div >
234+ </ >
265235 ) }
266- < CompatibilitySortWidget
267- className = "text-sm sm:flex mt-4"
268- sort = { sort }
269- setSort = { setSort }
270- user = { user }
271- profile = { profile }
272- />
273236 { compatibilityScore && (
274237 < CompatibleBadge compatibility = { compatibilityScore } className = { 'mt-5 mr-4' } />
275238 ) }
276239 </ Row >
277- { answeredQuestions . length < = 0 ? (
240+ { answeredQuestions . length = = 0 ? (
278241 < span className = "text-ink-600 text-sm" >
279242 { isCurrentUser
280243 ? t (
0 commit comments