Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 사이트 이름 클릭 시 사이트로 이동하게 수정 #293

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/search/components/ResultList/ResultList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useScrollObserve } from '@/hooks/useScrollObserve';
import { useGetSearch } from '@/search/hooks/useGetSearch';
import { NoResult } from '@/search/pages/NoResult/NoResult';
import { SearchResponse } from '@/search/types/ResultListItem.type';
import { extractOrigin } from '@/search/utils/extractOrigin';

import NoResultFallback from '../FallbackComponent/NoResultFallback';

Expand Down Expand Up @@ -38,6 +39,7 @@ export const ResultList = () => {
{data?.pages.map((page) => {
return page.resultList.map((item, itemIndex) => {
const isLastItem = page.resultList.length === itemIndex + 1;
const domain = extractOrigin(item.link);
return (
<div key={item.id}>
<LogClick
Expand All @@ -59,6 +61,7 @@ export const ResultList = () => {
>
<ResultListItem
{...item}
domain={domain}
onClick={() => window.open(item.link)}
ref={isLastItem ? lastElementRef : null}
/>
Expand Down
11 changes: 11 additions & 0 deletions src/search/components/ResultList/ResultListItem.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ export const StyledLinkImage = styled.img`
export const StyledLinkTitle = styled.span`
${(props) => props.theme.typo.body1}
color: ${(props) => props.theme.color.textSecondary};
text-decoration: none;

&:hover {
text-decoration: underline;
}
`;

export const StyledDomain = styled.div`
cursor: pointer;
display: flex;
align-items: center;
`;

export const StyledDate = styled.span`
Expand Down
31 changes: 21 additions & 10 deletions src/search/components/ResultList/ResultListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,48 @@ import { onErrorImg } from '@/search/utils/onErrorImg';

import {
StyledContent,
StyledContentWrap,
StyledDate,
StyledLinkImageWrap,
StyledDomain,
StyledInformationWrap,
StyledLinkImage,
StyledLinkImageWrap,
StyledLinkTitle,
StyledResultListItem,
StyledThumbnail,
StyledThumbnailCountBox,
StyledThumbnailImage,
StyledTitle,
StyledContentWrap,
StyledInformationWrap,
} from './ResultListItem.style';

interface ResultListItemProps
extends Pick<React.ComponentProps<'div'>, 'onClick'>,
ResultListItemResponse {}
ResultListItemResponse {
domain?: string;
}

export const ResultListItem = forwardRef<HTMLDivElement, ResultListItemProps>(
({ title, content, date, thumbnail, favicon, source, onClick }, ref) => {
({ title, content, date, thumbnail, favicon, source, domain, onClick }, ref) => {
const isVerticalLayout = thumbnail.length >= RESULT_LIST_ITEM_THUMBNAIL_LENGTH;
const isHorizontalLayout = !isVerticalLayout && thumbnail.length > 0;
const handleDomainClick = (e: React.MouseEvent) => {
e.stopPropagation();
if (domain) {
window.open(domain);
}
};

return (
<StyledResultListItem ref={ref} onClick={onClick}>
<StyledContentWrap $isHorizontalLayout={isHorizontalLayout}>
<StyledInformationWrap>
<StyledLinkImageWrap>
<StyledLinkImage src={favicon || '/'} alt="favicon" onError={onErrorImg} />
</StyledLinkImageWrap>
<Spacing direction="horizontal" size={4} />
<StyledLinkTitle>{source}</StyledLinkTitle>
<StyledDomain onClick={handleDomainClick}>
<StyledLinkImageWrap>
<StyledLinkImage src={favicon || '/'} alt="favicon" onError={onErrorImg} />
</StyledLinkImageWrap>
<Spacing direction="horizontal" size={4} />
<StyledLinkTitle>{source}</StyledLinkTitle>
</StyledDomain>
<Spacing direction="horizontal" size={4} />
<StyledDate>·</StyledDate>
<Spacing direction="horizontal" size={4} />
Expand Down
8 changes: 8 additions & 0 deletions src/search/utils/extractOrigin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const extractOrigin = (url: string): string => {
try {
const { origin } = new URL(url);
return origin;
} catch (error) {
return url;
}
};