Skip to content

Commit

Permalink
feat: 채널 수정 모달 구현 및 프로필 페이지 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
GihoKo committed Jul 19, 2024
1 parent ac9208f commit d256604
Show file tree
Hide file tree
Showing 31 changed files with 644 additions and 511 deletions.
2 changes: 1 addition & 1 deletion src/apis/hooks/useDeleteChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function useDeleteChannel() {
mutationFn: ({ channelId }) => deleteChannel(channelId),
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: ['myOwnChannels', 'myChannels'],
queryKey: ['channels'],
});
},
});
Expand Down
11 changes: 11 additions & 0 deletions src/apis/hooks/useGetChannelById.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useQuery } from '@tanstack/react-query';
import { Channel } from '../../types/channel';
import { getChannelById } from '../services/channel';

export default function useGetChannelById(channelId: string | undefined) {
const queryKey = ['channels', channelId];
return useQuery<Channel, Error>({
queryKey: queryKey,
queryFn: () => getChannelById(channelId),
});
}
2 changes: 1 addition & 1 deletion src/apis/hooks/useGetMyChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getMyChannelList } from '../services/user';
import { Channel } from '../../types/channel';

export default function useGetMyChannel(userId: string | undefined) {
const queryKey = ['myChannels'];
const queryKey = ['channels'];
return useQuery<Channel[], Error>({
queryKey: queryKey,
queryFn: () => getMyChannelList(userId),
Expand Down
2 changes: 1 addition & 1 deletion src/apis/hooks/useGetMyOwnChannels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getMyOwnChannels } from '../services/user';
import { Channel } from '../../types/channel';

export default function useGetMyOwnChannels(userId: string) {
const queryKey = ['myOwnChannels', 'myChannels'];
const queryKey = ['channels'];
return useQuery<Channel[], Error>({
queryKey: queryKey,
queryFn: () => getMyOwnChannels(userId),
Expand Down
6 changes: 3 additions & 3 deletions src/apis/hooks/useRenewTokens.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useQuery } from '@tanstack/react-query';
import { renewTokens } from '../services/auth';

interface AccessToken {
accessToken: string;
interface ApplicationAccessToken {
applicationAccessToken: string;
}

export default function useRenewTokens() {
const queryKey = ['tokens'];
return useQuery<AccessToken, Error>({
return useQuery<ApplicationAccessToken, Error>({
queryKey: queryKey,
queryFn: renewTokens,
});
Expand Down
5 changes: 2 additions & 3 deletions src/apis/hooks/useUpdateChannel.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { Channel } from '../../types/channel';
import { updateChannel } from '../services/channel';

interface updateChannelParams {
channelId: string;
channel: Channel;
channel: FormData;
}

export default function useUpdateChannel() {
Expand All @@ -13,7 +12,7 @@ export default function useUpdateChannel() {
mutationFn: ({ channelId, channel }) => updateChannel(channelId, channel),
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: ['myOwnChannels, myChannels'],
queryKey: ['channels'],
});
},
});
Expand Down
7 changes: 2 additions & 5 deletions src/apis/services/auth.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { axiosInstance } from '../instances';
import axios from 'axios';

interface RenewTokenResponse {
applicationAccessToken: string;
}

// accessToken 만료시 token들을 재발급
export const renewTokens = async () => {
try {
const response = await axiosInstance.post<RenewTokenResponse>('/auth/renewTokens');
const response = await axiosInstance.post('/auth/renewTokens');
return response.data.applicationAccessToken;
} catch (error: unknown) {
if (axios.isAxiosError(error)) {
console.error(error.response?.status);
window.location.href = '/signIn';
throw new Error('토큰이 만료되었습니다. 다시 로그인해주세요.');
}
return null;
}
Expand Down
12 changes: 8 additions & 4 deletions src/apis/services/channel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { axiosInstanceWithToken } from '../instances';
import { Channel } from '../../types/channel';
import { Music } from '@/types/music';

export const getAllchannelLists = async () => {
Expand All @@ -11,7 +10,7 @@ export const getAllchannelLists = async () => {
}
};

export const getChannelById = async (channelId: string) => {
export const getChannelById = async (channelId: string | undefined) => {
try {
const response = await axiosInstanceWithToken.get(`/channels/${channelId}`);
return response.data;
Expand All @@ -33,9 +32,14 @@ export const createChannel = async (channel: FormData) => {
}
};

export const updateChannel = async (channelId: string, channel: Channel) => {
export const updateChannel = async (channelId: string, channel: FormData) => {
console.log(channelId, channel);
try {
const response = await axiosInstanceWithToken.patch(`/channels/${channelId}`, { channel });
const response = await axiosInstanceWithToken.patch(`/channels/${channelId}`, channel, {
headers: {
'Content-Type': 'multipart/form-data',
},
});
return response.data;
} catch (error) {
console.error(error);
Expand Down
42 changes: 42 additions & 0 deletions src/components/Atoms/Modal/StyledComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,45 @@ export const Tag = styled.div`
background-color: var(--mint7);
}
`;

export const ChannelImageWrapper = styled.button`
border-radius: 16px;
width: 120px;
height: 120px;
overflow: hidden;
padding: 0;
cursor: pointer;
img {
width: 100%;
height: 100%;
object-fit: cover;
cursor: pointer;
}
`;

export const EmptyImage = styled.div`
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
color: var(--grey-grey600);
background-color: var(--grey-grey150);
cursor: pointer;
&:hover {
background-color: var(--grey-grey200);
}
`;

export const ChannelImageLabel = styled(Label)``;

export const FileInput = styled.input`
display: none;
`;
Empty file removed src/components/Molecules/.gitkeep
Empty file.
46 changes: 46 additions & 0 deletions src/components/Molecules/Description.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import styled from 'styled-components';

interface DescriptionProps {
title: string;
text: string;
}

export default function Description({ title, text }: DescriptionProps) {
return (
<Wrapper>
<Title>{title}</Title>
<Text>{text}</Text>
</Wrapper>
);
}

const Wrapper = styled.div`
border-radius: 16px;
border: 1px solid var(--grey-grey300);
width: 320px;
height: 160px;
display: flex;
flex-direction: column;
gap: 16px;
padding: 32px;
background-color: var(--grey-grey150);
@media (max-width: 992px) {
width: 100%;
padding: 16px;
}
`;

const Title = styled.div`
font-size: 20px;
color: var(--grey-grey900);
`;

const Text = styled.span`
font-size: 16px;
color: var(--grey-grey600);
`;
2 changes: 1 addition & 1 deletion src/components/Organisms/Modal/CreateChannelModal.hook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export default function useCreateChannelModal() {
description: '',
image: '',
});
const [tagValue, setTagValue] = useState<string>('');
const [previewChannelImageUrl, setPreviewChannelImageUrl] = useState<string | null>(null);
const fileInputRef = useRef<HTMLInputElement>(null);
const [profileImageFile, setProfileImageFile] = useState<File | null>(null);
const [tagValue, setTagValue] = useState<string>('');
const uploadCreateChannel = useCreateChannel();

const handleChannelImageClick = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
Expand Down
55 changes: 7 additions & 48 deletions src/components/Organisms/Modal/CreateChannelModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// libraries
import styled from 'styled-components';

// hooks
import useCreateChannelModal from './CreateChannelModal.hook';

Expand All @@ -18,14 +15,18 @@ import {
ButtonWrapper,
TagContainer,
Tag,
ChannelImageLabel,
ChannelImageWrapper,
EmptyImage,
FileInput,
} from '../../Atoms/Modal/StyledComponents';

export default function CreateChannelModal() {
// logics
const hookData = useCreateChannelModal();
const logics = useCreateChannelModal();

// useCreateChannelModal hook에서 null을 반환할 수 있으므로 null 체크
if (!hookData) return null;
if (!logics) return null;

const {
channelData,
Expand All @@ -40,7 +41,7 @@ export default function CreateChannelModal() {
handleDeleteTag,
handleSubmit,
closeModal,
} = hookData;
} = logics;

// view
return (
Expand Down Expand Up @@ -131,45 +132,3 @@ export default function CreateChannelModal() {
</Dimmed>
);
}

const ChannelImageWrapper = styled.button`
border-radius: 16px;
width: 120px;
height: 120px;
overflow: hidden;
padding: 0;
cursor: pointer;
img {
width: 100%;
height: 100%;
object-fit: cover;
cursor: pointer;
}
`;

const EmptyImage = styled.div`
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
color: var(--grey-grey600);
background-color: var(--grey-grey150);
cursor: pointer;
&:hover {
background-color: var(--grey-grey200);
}
`;

const ChannelImageLabel = styled(Label)``;

const FileInput = styled.input`
display: none;
`;
Loading

0 comments on commit d256604

Please sign in to comment.