mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
related items without cover now has letters
This commit is contained in:
parent
0f3ac203f7
commit
eade3efc7c
4 changed files with 34 additions and 5 deletions
|
@ -5,6 +5,7 @@ import { getURL, getPrettyDate } from '~/utils/dom';
|
|||
import { Link } from 'react-router-dom';
|
||||
import { URLS, PRESETS } from '~/constants/urls';
|
||||
import classNames from 'classnames';
|
||||
import { NodeRelatedItem } from '~/components/node/NodeRelatedItem';
|
||||
|
||||
interface IProps {
|
||||
recent: IFlowState['recent'];
|
||||
|
@ -31,10 +32,10 @@ const FlowRecent: FC<IProps> = ({ recent, updated }) => (
|
|||
{recent &&
|
||||
recent.slice(0, 20).map(node => (
|
||||
<Link key={node.id} className={styles.item} to={URLS.NODE_URL(node.id)}>
|
||||
<div
|
||||
className={styles.thumb}
|
||||
style={{ backgroundImage: `url("${getURL({ url: node.thumbnail }, PRESETS.avatar)}")` }}
|
||||
/>
|
||||
<div className={styles.thumb}>
|
||||
<NodeRelatedItem item={node} />
|
||||
</div>
|
||||
|
||||
<div className={styles.info}>
|
||||
<div className={styles.title}>{node.title}</div>
|
||||
<div className={styles.comment}>{getPrettyDate(node.created_at)}</div>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
box-sizing: border-box;
|
||||
transition: background-color 0.5s;
|
||||
|
||||
@include tablet {
|
||||
@include desktop {
|
||||
height: 64px;
|
||||
padding: 0 $gap;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,18 @@ type IProps = RouteComponentProps & {
|
|||
item: Partial<INode>;
|
||||
};
|
||||
|
||||
const getTitleLetters = (title: string): string => {
|
||||
const words = title.split(' ');
|
||||
|
||||
return words.length > 1
|
||||
? words
|
||||
.slice(0, 2)
|
||||
.map(word => word[0])
|
||||
.join('')
|
||||
.toUpperCase()
|
||||
: words[0].substr(0, 2).toUpperCase();
|
||||
};
|
||||
|
||||
const NodeRelatedItemUnconnected: FC<IProps> = memo(({ item, history }) => {
|
||||
const [is_loaded, setIsLoaded] = useState(false);
|
||||
const onClick = useCallback(() => history.push(URLS.NODE_URL(item.id)), [item, history]);
|
||||
|
@ -25,6 +37,8 @@ const NodeRelatedItemUnconnected: FC<IProps> = memo(({ item, history }) => {
|
|||
style={{ backgroundImage: `url("${getURL({ url: item.thumbnail }, PRESETS.avatar)}")` }}
|
||||
/>
|
||||
|
||||
{!item.thumbnail && <div className={styles.letters}>{getTitleLetters(item.title)}</div>}
|
||||
|
||||
<img
|
||||
src={getURL({ url: item.thumbnail }, PRESETS.avatar)}
|
||||
alt="loader"
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
border-radius: $cell_radius;
|
||||
cursor: pointer;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
|
||||
img {
|
||||
position: absolute;
|
||||
|
@ -28,3 +29,16 @@
|
|||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.letters {
|
||||
position: absolute;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
font: $font_24_semibold;
|
||||
opacity: 0.2;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue