Skip to content

Commit

Permalink
Merge pull request #24 from sryung1225/dev
Browse files Browse the repository at this point in the history
검색 결과 개선 (#4 #23)
  • Loading branch information
sryung1225 authored Dec 27, 2023
2 parents 7107550 + e441194 commit 28e9aca
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const router = createBrowserRouter([
element: <Profile />,
},
{
path: `/search/:searchKeyword`,
path: `/search`,
element: <SearchResult />,
},
],
Expand Down
3 changes: 3 additions & 0 deletions src/assets/images/i-change.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 8 additions & 4 deletions src/components/profile/edit-profile-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import CompressImage from '@util/compress-image.tsx';
import useEscClose from '@util/use-esc-close.tsx';
import * as S from '@style/profile-form.ts';
import { ReactComponent as IconUser } from '@img/i-user.svg';
import { ReactComponent as IconChange } from '@img/i-change.svg';
import { ReactComponent as LoadingSpinner } from '@img/loading-spinner-mini.svg';

interface IEditProfileForm extends Pick<IUser, 'userAvatar' | 'userName'> {
Expand Down Expand Up @@ -97,19 +98,22 @@ export default function EditProfileForm({
return (
<S.Form onSubmit={onSubmit}>
{avatarPreview ? (
<>
<S.AttachAvatar>
<S.AttachAvatarPreview
src={avatarPreview}
alt="프로필이미지 미리보기"
width="120"
height="120"
/>
<S.AttachAvatarDelete type="button" onClick={onAvatarDelete} />
</>
<S.AttachAvatarChange htmlFor="avatar_edit">
<IconChange />
</S.AttachAvatarChange>
</S.AttachAvatar>
) : (
<S.AttachAvatarButton htmlFor="avatar_edit">
<S.AttachAvatarLabel htmlFor="avatar_edit">
<IconUser />
</S.AttachAvatarButton>
</S.AttachAvatarLabel>
)}
<S.AttachAvatarInput
onChange={onAvatarChange}
Expand Down
14 changes: 11 additions & 3 deletions src/components/search-result/search-timeline.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect, useState } from 'react';
import { useLocation } from 'react-router-dom';
import {
collection,
getDocs,
Expand All @@ -7,16 +8,21 @@ import {
query,
where,
} from 'firebase/firestore';
import { useRecoilValue } from 'recoil';
import { db } from '@/firebase.ts';
import { useRecoilValue } from 'recoil';
import { searchKeywordAtom } from '@/atoms.tsx';
import Tweet from '@compo/home/tweet.tsx';
import ITweet from '@type/ITweet.ts';
import * as S from '@style/timeline.ts';

export default function SearchTimeline() {
const location = useLocation();
const [tweets, setTweets] = useState<ITweet[]>([]);
const searchKeyword = useRecoilValue(searchKeywordAtom);
const searchKeywordFromLocation = decodeURIComponent(
location.search.slice(7),
);
const searchKeywordAtomValue = useRecoilValue(searchKeywordAtom);
const searchKeyword = searchKeywordFromLocation || searchKeywordAtomValue;
const fetchTweets = async () => {
const tweetsQuery = query(
collection(db, 'tweets'),
Expand Down Expand Up @@ -50,6 +56,8 @@ export default function SearchTimeline() {
))}
</S.TimelineWrapper>
) : (
<S.Text>검색 결과가 없습니다.</S.Text>
<S.Text>
[<span>{searchKeyword}</span>] 에 대한 검색 결과가 없습니다.
</S.Text>
);
}
16 changes: 5 additions & 11 deletions src/components/search.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react';
import { useRecoilState } from 'recoil';
import React, { useState } from 'react';
import { useSetRecoilState } from 'recoil';
import { useNavigate } from 'react-router-dom';
import { searchKeywordAtom } from '@/atoms.tsx';
import WindowTop from '@compo/window-top.tsx';
Expand All @@ -10,22 +10,16 @@ import { ReactComponent as IconSearch } from '@img/i-search.svg';
export default function Search() {
const navigate = useNavigate();
const [searchValue, setSearchValue] = useState('');
const [searchKeyword, setSearchKeyword] = useRecoilState(searchKeywordAtom);
const setSearchKeyword = useSetRecoilState(searchKeywordAtom);
const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setSearchValue(e.target.value);
};
const onSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
const onSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (searchValue === '') return;
setSearchKeyword(searchValue);
setSearchValue('');
navigate(`/search/searchKeyword=${searchKeyword}`);
navigate(`/search?query=${searchValue}`);
};
useEffect(() => {
if (searchKeyword) {
navigate(`/search/searchKeyword=${searchKeyword}`);
}
}, [searchKeyword, navigate]);
return (
<W.Window>
<WindowTop />
Expand Down
34 changes: 30 additions & 4 deletions src/styles/profile-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,33 @@ export const Form = styled.form`
align-items: center;
`;

export const AttachAvatarPreview = styled.img`
export const AttachAvatar = styled.div`
position: relative;
width: 120px;
height: 120px;
margin-bottom: 20px;
`;

export const AttachAvatarPreview = styled.img`
width: 120px;
height: 120px;
object-fit: cover;
border-radius: 50%;
`;

export const AttachAvatarDelete = styled.button`
export const AttachAvatarButton = styled.button`
position: absolute;
top: 0;
right: 70px;
width: 25px;
height: 25px;
background-color: ${primaryColor};
border: 2px solid ${whiteColor};
border-radius: 50%;
`;

export const AttachAvatarDelete = styled(AttachAvatarButton)`
left: 10px;
&::before,
&::after {
content: '';
Expand All @@ -47,7 +57,23 @@ export const AttachAvatarDelete = styled.button`
}
`;

export const AttachAvatarButton: React.ComponentType<
export const AttachAvatarChange: React.ComponentType<
React.HTMLProps<HTMLLabelElement>
> = styled(AttachAvatarButton).attrs(() => ({ as: 'label' }))`
right: 10px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
svg {
width: 15px;
height: 15px;
stroke: ${whiteColor};
stroke-width: 3px;
}
`;

export const AttachAvatarLabel: React.ComponentType<
React.HTMLProps<HTMLLabelElement>
> = styled(Avatar).attrs(() => ({
as: 'label',
Expand Down
5 changes: 5 additions & 0 deletions src/styles/timeline.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styled from 'styled-components';
import { primaryColor } from '@style/global.ts';

export const TimelineWrapper = styled.ul`
display: block;
Expand All @@ -9,4 +10,8 @@ export const TimelineWrapper = styled.ul`
export const Text = styled.p`
margin: 20px 0;
text-align: center;
span {
color: ${primaryColor};
font-weight: 600;
}
`;

0 comments on commit 28e9aca

Please sign in to comment.