import * as React from 'react' import { isLofter, isAndroid } from 'nw-detect' import { openAppLofter } from 'nw-app-lofter' import { cancelInvite } from '../actions' import { Image } from '../image' import { formatNumber } from '../../utils/format' import { ColDetail } from '../type' import { Container, Header, HeaderImageBorder, HeaderTag, HeaderCount, Title, Description, InfoContainer, HeaderImageBg1, HeaderImageBg2, UserInfo, HeaderInfoContainer, Button, EmptyDescription, LoadingCol } from './index.style' interface Props { colDetail: ColDetail; key: React.Key; className: string; type: 'me' | 'other'; refresh?: () => any; } export const CollectionItem = ({ key, colDetail, className, type, refresh }: Props) => { const goToUserPage = () => { const { blogName } = colDetail?.blogInfo if (!blogName) return if (isLofter()) { window.location.href = `lofter://${blogName}.lofter.com/` } else { openAppLofter({ path: 'homepage', query: { id: blogName } }) } } const gotToCol = () => { let { blogName } = colDetail?.blogInfo const { collectionId } = colDetail // 去除 blogName 中所有的 - 字符 let reg = /(-)/g blogName = blogName.replace(reg, '') if (!blogName) return let link = `http://www.lofter.com/collection/${blogName}/?op=collectionDetail&collectionId=${collectionId}` if (isAndroid()) { link = `http://www.lofter.com/collection/${blogName}/?op=collectionDetail&collectionId=${collectionId}&sort=1&invitationId=0` } if (isLofter()) { window.location.href = link } else { openAppLofter({ path: 'webview', query: { url: link } }) } } const cancel = () => { cancelInvite(colDetail.id) .then(() => { refresh?.() }) } return ( { colDetail?.name ? ( <>
{ colDetail?.tags ? ( {`# ${colDetail.tags.split(',')[0]}`} ) : null } { colDetail?.invitedCount && ( {formatNumber(colDetail?.invitedCount)} ) }
{colDetail?.name} { colDetail?.description ? ( {colDetail?.description} ) : }
{colDetail?.blogInfo.blogNickName}
{ type === 'me' ? ( ) : ( ) }
) : ( { colDetail.id ? ( { colDetail.id }无数据 ) : null } { colDetail.id === 0 ? ( 请输入合集 id ) : null }
) } ) }