Skip to content

Commit

Permalink
[Refactor][Reaction] 인사이트 반응하기 변경점 적용 (#265)
Browse files Browse the repository at this point in the history
- 한번이라도 반응했으면 버튼 ui를 통해 해당 기록을 보여줍니다.
  • Loading branch information
ysh4296 authored Nov 26, 2023
1 parent 6be4e27 commit 1db040a
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 54 deletions.
20 changes: 14 additions & 6 deletions src/components/emoticons/ReactIconButton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable indent */
import React, { useState, useRef, useEffect, useMemo } from 'react';
import { Animated, Easing } from 'react-native';
import { SvgXml } from 'react-native-svg';
import { useMutation } from '@tanstack/react-query';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { Pressable, Text, StyleSheet } from 'react-native';
import { InsightAPI } from '../../utils/api/InsightAPI';
import { FlyingView, ObjectConfig } from 'react-native-flying-objects';
Expand All @@ -12,16 +13,20 @@ interface ReactIconButtonProps {
color: string;
taps?: number;
name: string;
clicked: boolean;
insightId: number;
}

const ReactIconButton = ({ xml, color, taps, name, insightId }: ReactIconButtonProps) => {
const ReactIconButton = ({ xml, color, taps, name, clicked, insightId }: ReactIconButtonProps) => {
const opacityValue = useRef(new Animated.Value(0)).current;
const [object, setObject] = useState<ObjectConfig[]>([]);
const [text, setText] = useState<number>();
const [tab, setTab] = useState<boolean>(false);

const { mutate: insightReact } = useMutation(InsightAPI.react, {
onSuccess: (response) => {
setText(response?.data.count);
setTab(true);
},
});

Expand Down Expand Up @@ -75,10 +80,13 @@ const ReactIconButton = ({ xml, color, taps, name, insightId }: ReactIconButtonP
<Pressable onPress={handleClick}>
<Animated.View
style={{
backgroundColor: opacityValue.interpolate({
inputRange: [0, 1],
outputRange: [theme.colors.graphic.white, color],
}),
backgroundColor:
clicked || tab
? color
: opacityValue.interpolate({
inputRange: [0, 1],
outputRange: [theme.colors.graphic.white, color],
}),
padding: 8,
marginTop: 12,
...styles.Button,
Expand Down
3 changes: 2 additions & 1 deletion src/screens/Feed/FeedItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import MiniProfile from '../../components/profile/MiniProfile';
import FeedLinkWithBookMark from './FeedLinkCard';
import FeedVerticalDots from './FeedVerticalDots';
import FeedTextContent from './FeedTextContent';
import { REACTIONS } from './constant';
import { REACTIONS } from '../detailedPost/constant';
import ReactIconButton from '../../components/emoticons/ReactIconButton';
import { useNavigation } from '@react-navigation/native';
import { StackNavigationProp } from '@react-navigation/stack';
Expand Down Expand Up @@ -71,6 +71,7 @@ const FeedItem = ({ insight, localId, onBookMarkClick }: FeedItemProps) => {
xml={react.xml}
color={react.color}
taps={reaction[react.reaction]}
clicked={reaction[react.clicked]}
name={react.name}
insightId={id}
/>
Expand Down
46 changes: 0 additions & 46 deletions src/screens/Feed/constant.ts

This file was deleted.

8 changes: 7 additions & 1 deletion src/screens/detailedPost/DetailedPostScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import removeEscapeSequences from '../../utils/helper/strings/removeEscapeSequen
import { getUserId } from '../../utils/hooks/asyncStorage/Login';
import CommentList from './CommentList';

const COMMENT_LIMIT = 5;
const COMMENT_LIMIT = 10;

const DetailedPostScreen = ({ navigation, route }) => {
const { insightId, initialInsight } = route.params;
Expand Down Expand Up @@ -191,6 +191,12 @@ const DetailedPostScreen = ({ navigation, route }) => {
heart: 33,
sad: 78,
surprise: 45,
isClapClicked: false,
isHeartClicked: false,
isSadClicked: false,
isSurpriseClicked: false,
isFireClicked: false,
isEyesClicked: false,
};

if (isInsightError || isCountError || isChallengeRecordError) {
Expand Down
1 change: 1 addition & 0 deletions src/screens/detailedPost/DetailedPostSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ const DetailedPostSection = ({
xml={react.xml}
color={react.color}
taps={reaction[react.reaction]}
clicked={reaction[react.clicked]}
name={react.name}
insightId={insightId}
/>
Expand Down
6 changes: 6 additions & 0 deletions src/screens/detailedPost/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,47 @@ export const REACTIONS: Record<string, any>[] = [
{
name: 'CLAP',
reaction: 'clap',
clicked: 'isClapClicked',
xml: ClapRoundOffSmallXml,
bezier: [0.5, 1.8, 0.4, 1.0],
color: theme.colors.graphic.sky,
},
{
name: 'HEART',
reaction: 'heart',
clicked: 'isHeartClicked',
xml: HeartRoundOffSmallXml,
bezier: [0.5, 1.8, 0.4, 1.12],
color: theme.colors.graphic.green,
},
{
name: 'SAD',
reaction: 'sad',
clicked: 'isSadClicked',
xml: SadRoundOffSmallXml,
bezier: [0.5, 1.8, 0.4, 1.24],
color: theme.colors.graphic.purple,
},
{
name: 'SURPRISE',
reaction: 'surprise',
clicked: 'isSurpriseClicked',
xml: SurpriseRoundOffSmallXml,
bezier: [0.5, 1.8, 0.4, 1.36],
color: theme.colors.graphic.coral,
},
{
name: 'EYES',
reaction: 'eyes',
clicked: 'isEyesClicked',
xml: EyesRoundOffSmallXml,
bezier: [0.5, 1.8, 0.4, 1.48],
color: theme.colors.graphic.marine,
},
{
name: 'FIRE',
reaction: 'fire',
clicked: 'isFireClicked',
xml: FireRoundOffSmallXml,
bezier: [0.5, 1.8, 0.4, 1.6],
color: theme.colors.graphic.orange,
Expand Down
6 changes: 6 additions & 0 deletions src/types/Feed/Feedinsights.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ interface Reaction {
surprise: number;
fire: number;
eyes: number;
isClapClicked: boolean;
isHeartClicked: boolean;
isSadClicked: boolean;
isSurpriseClicked: boolean;
isFireClicked: boolean;
isEyesClicked: boolean;
}

interface InsightWriter {
Expand Down

0 comments on commit 1db040a

Please sign in to comment.