diff --git a/web/components/answers/answer-compatibility-question-content.tsx b/web/components/answers/answer-compatibility-question-content.tsx index f1a12262..d1b1212f 100644 --- a/web/components/answers/answer-compatibility-question-content.tsx +++ b/web/components/answers/answer-compatibility-question-content.tsx @@ -1,22 +1,22 @@ -import { RadioGroup } from '@headlessui/react' -import { UserIcon } from '@heroicons/react/solid' +import {RadioGroup} from '@headlessui/react' +import {UserIcon} from '@heroicons/react/solid' import clsx from 'clsx' -import { Row as rowFor, run } from 'common/supabase/utils' -import { User } from 'common/user' -import { shortenNumber } from 'common/util/format' -import { sortBy } from 'lodash' -import { useState } from 'react' -import { Button } from 'web/components/buttons/button' -import { Col } from 'web/components/layout/col' -import { SCROLLABLE_MODAL_CLASS } from 'web/components/layout/modal' -import { Row } from 'web/components/layout/row' -import { ExpandingInput } from 'web/components/widgets/expanding-input' -import { RadioToggleGroup } from 'web/components/widgets/radio-toggle-group' -import { Tooltip } from 'web/components/widgets/tooltip' -import { QuestionWithCountType } from 'web/hooks/use-questions' -import { track } from 'web/lib/service/analytics' -import { db } from 'web/lib/supabase/db' -import { filterKeys } from '../questions-form' +import {Row as rowFor, run} from 'common/supabase/utils' +import {User} from 'common/user' +import {shortenNumber} from 'common/util/format' +import {sortBy} from 'lodash' +import {useState} from 'react' +import {Button} from 'web/components/buttons/button' +import {Col} from 'web/components/layout/col' +import {SCROLLABLE_MODAL_CLASS} from 'web/components/layout/modal' +import {Row} from 'web/components/layout/row' +import {ExpandingInput} from 'web/components/widgets/expanding-input' +import {RadioToggleGroup} from 'web/components/widgets/radio-toggle-group' +import {Tooltip} from 'web/components/widgets/tooltip' +import {QuestionWithCountType} from 'web/hooks/use-questions' +import {track} from 'web/lib/service/analytics' +import {db} from 'web/lib/supabase/db' +import {filterKeys} from '../questions-form' import toast from "react-hot-toast"; export type CompatibilityAnswerSubmitType = Omit< @@ -72,7 +72,25 @@ export const submitCompatibilityAnswer = async ( console.error('Failed to upsert love_compatibility_answers:', error); toast.error('Error submitting. Try again?') } +} +export const deleteCompatibilityAnswer = async ( + id: number, + userId: string +) => { + if (!userId || !id) return + try { + await run( + db + .from('love_compatibility_answers') + .delete() + .match({id: id, creator_id: userId}) + ) + await track('delete compatibility question', {id}); + } catch (error) { + console.error('Failed to delete prompt answer:', error); + toast.error('Error deleting. Try again?') + } } function getEmptyAnswer(userId: string, questionId: number) { @@ -85,6 +103,7 @@ function getEmptyAnswer(userId: string, questionId: number) { importance: -1, } } + export function AnswerCompatibilityQuestionContent(props: { compatibilityQuestion: QuestionWithCountType user: User @@ -108,7 +127,7 @@ export function AnswerCompatibilityQuestionContent(props: { } = props const [answer, setAnswer] = useState( (props.answer as CompatibilityAnswerSubmitType) ?? - getEmptyAnswer(user.id, compatibilityQuestion.id) + getEmptyAnswer(user.id, compatibilityQuestion.id) ) const [loading, setLoading] = useState(false) @@ -158,7 +177,7 @@ export function AnswerCompatibilityQuestionContent(props: { > {shortenedPopularity} - + )} @@ -173,7 +192,7 @@ export function AnswerCompatibilityQuestionContent(props: { - setAnswer({ ...answer, multiple_choice: choice }) + setAnswer({...answer, multiple_choice: choice}) } options={optionOrder} /> @@ -183,7 +202,7 @@ export function AnswerCompatibilityQuestionContent(props: { - setAnswer({ ...answer, pref_choices: choice }) + setAnswer({...answer, pref_choices: choice}) } options={optionOrder} /> @@ -194,7 +213,7 @@ export function AnswerCompatibilityQuestionContent(props: { currentChoice={answer.importance ?? -1} choicesMap={IMPORTANCE_CHOICES} setChoice={(choice: number) => - setAnswer({ ...answer, importance: choice }) + setAnswer({...answer, importance: choice}) } indexColors={IMPORTANCE_RADIO_COLORS} /> @@ -208,14 +227,14 @@ export function AnswerCompatibilityQuestionContent(props: { rows={3} value={answer.explanation ?? ''} onChange={(e) => - setAnswer({ ...answer, explanation: e.target.value }) + setAnswer({...answer, explanation: e.target.value}) } /> {noSkip ? ( -
+
) : (
{getStringKeyFromNumValue(importance, IMPORTANCE_CHOICES)} @@ -629,7 +628,7 @@ function ImportanceButton(props: { onClick: () => void className?: string }) { - const { importance, onClick, className } = props + const {importance, onClick, className} = props return ( ) } + function getStringKeyFromNumValue( value: number, map: Record diff --git a/web/components/profile/profile-profile-header.tsx b/web/components/profile/profile-header.tsx similarity index 99% rename from web/components/profile/profile-profile-header.tsx rename to web/components/profile/profile-header.tsx index 6490cc7b..0407a5d4 100644 --- a/web/components/profile/profile-profile-header.tsx +++ b/web/components/profile/profile-header.tsx @@ -21,7 +21,7 @@ import {api, updateProfile} from 'web/lib/api' import React, {useState} from 'react' import {VisibilityConfirmationModal} from './visibility-confirmation-modal' -export default function ProfileProfileHeader(props: { +export default function ProfileHeader(props: { user: User profile: Profile simpleView?: boolean diff --git a/web/components/profile/profile-profile.tsx b/web/components/profile/profile-info.tsx similarity index 97% rename from web/components/profile/profile-profile.tsx rename to web/components/profile/profile-info.tsx index 60e08e82..901d110d 100644 --- a/web/components/profile/profile-profile.tsx +++ b/web/components/profile/profile-info.tsx @@ -1,5 +1,5 @@ import {ProfileCommentSection} from 'web/components/profile-comment-section' -import ProfileProfileHeader from 'web/components/profile/profile-profile-header' +import ProfileHeader from 'web/components/profile/profile-header' import ProfileCarousel from 'web/components/profile-carousel' import {Col} from 'web/components/layout/col' import {Row} from 'web/components/layout/row' @@ -16,7 +16,7 @@ import {Content} from "web/components/widgets/editor"; import {JSONContent} from "@tiptap/core"; import React from "react"; -export function ProfileProfile(props: { +export function ProfileInfo(props: { profile: Profile user: User refreshProfile: () => void @@ -63,7 +63,7 @@ export function ProfileProfile(props: { return ( <> - {profile ? ( -