mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
added imagecaching
This commit is contained in:
parent
88f50e3348
commit
1320f0851f
16 changed files with 43 additions and 35 deletions
|
@ -6,6 +6,7 @@ import { Card } from '../Card';
|
|||
import { IUser } from '~/redux/auth/types';
|
||||
import { getURL } from '~/utils/dom';
|
||||
import path from 'ramda/es/path';
|
||||
import { PRESETS } from '~/constants/urls';
|
||||
|
||||
type IProps = HTMLAttributes<HTMLDivElement> & {
|
||||
// photo?: string;
|
||||
|
@ -33,7 +34,7 @@ const CommentWrapper: FC<IProps> = ({
|
|||
<div className={styles.thumb}>
|
||||
<div
|
||||
className={styles.thumb_image}
|
||||
style={{ backgroundImage: `url("${getURL(path(['photo'], user))}")` }}
|
||||
style={{ backgroundImage: `url("${getURL(path(['photo'], user), PRESETS.avatar)}")` }}
|
||||
/>
|
||||
<div className={styles.thumb_user}>~{path(['username'], user)}</div>
|
||||
</div>
|
||||
|
|
|
@ -5,6 +5,7 @@ import { selectNode } from '~/redux/node/selectors';
|
|||
import { connect } from 'react-redux';
|
||||
import pick from 'ramda/es/pick';
|
||||
import { getURL } from '~/utils/dom';
|
||||
import { PRESETS } from '~/constants/urls';
|
||||
|
||||
const mapStateToProps = state => pick(['current_cover_image'], selectNode(state));
|
||||
|
||||
|
@ -15,7 +16,7 @@ const PageCoverUnconnected: FC<IProps> = memo(({ current_cover_image }) =>
|
|||
? createPortal(
|
||||
<div
|
||||
className={styles.wrap}
|
||||
style={{ backgroundImage: `url("${getURL(current_cover_image)}")` }}
|
||||
style={{ backgroundImage: `url("${getURL(current_cover_image, PRESETS.cover)}")` }}
|
||||
/>,
|
||||
document.body
|
||||
)
|
||||
|
|
|
@ -9,6 +9,7 @@ import * as UPLOAD_ACTIONS from '~/redux/uploads/actions';
|
|||
import { selectUploads } from '~/redux/uploads/selectors';
|
||||
import { getURL } from '~/utils/dom';
|
||||
import { Icon } from '~/components/input/Icon';
|
||||
import { PRESETS } from '~/constants/urls';
|
||||
|
||||
const mapStateToProps = state => {
|
||||
const { statuses, files } = selectUploads(state);
|
||||
|
@ -78,7 +79,7 @@ const EditorUploadCoverButtonUnconnected: FC<IProps> = ({
|
|||
setData({ ...data, cover: null });
|
||||
}, [setData, data]);
|
||||
|
||||
const background = data.cover ? getURL(data.cover) : null;
|
||||
const background = data.cover ? getURL(data.cover, PRESETS['300']) : null;
|
||||
const status = cover_temp && path([cover_temp], statuses);
|
||||
const preview = status && path(['preview'], status);
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import { SortableImageGridItem } from '~/components/editors/SortableImageGridIte
|
|||
import { IFile } from '~/redux/types';
|
||||
import { IUploadStatus } from '~/redux/uploads/reducer';
|
||||
import { getURL } from '~/utils/dom';
|
||||
import { PRESETS } from '~/constants/urls';
|
||||
|
||||
const SortableImageGrid = SortableContainer(
|
||||
({
|
||||
|
@ -27,7 +28,7 @@ const SortableImageGrid = SortableContainer(
|
|||
.filter(file => file && file.id)
|
||||
.map((file, index) => (
|
||||
<SortableImageGridItem key={file.id} index={index} collection={0}>
|
||||
<ImageUpload id={file.id} thumb={getURL(file)} onDrop={onDrop} />
|
||||
<ImageUpload id={file.id} thumb={getURL(file, PRESETS.cover)} onDrop={onDrop} />
|
||||
</SortableImageGridItem>
|
||||
))}
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ const Cell: FC<IProps> = ({
|
|||
}}
|
||||
onClick={onClick}
|
||||
>
|
||||
<img src={getURL({ url: thumbnail })} onLoad={onImageLoad} alt="" />
|
||||
<img src={getURL({ url: thumbnail }, PRESETS.cover)} onLoad={onImageLoad} alt="" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
@ -5,7 +5,7 @@ import classNames from 'classnames';
|
|||
import * as styles from './styles.scss';
|
||||
import { getURL } from '~/utils/dom';
|
||||
import { withRouter, RouteComponentProps } from 'react-router';
|
||||
import { URLS } from '~/constants/urls';
|
||||
import { URLS, PRESETS } from '~/constants/urls';
|
||||
import { Icon } from '~/components/input/Icon';
|
||||
|
||||
type IProps = RouteComponentProps & {
|
||||
|
@ -103,12 +103,12 @@ const FlowHeroUnconnected: FC<IProps> = ({ heroes, history }) => {
|
|||
[styles.is_visible]: loaded.includes(hero.id),
|
||||
[styles.is_active]: current === hero.id,
|
||||
})}
|
||||
style={{ backgroundImage: `url("${getURL({ url: hero.thumbnail })}")` }}
|
||||
style={{ backgroundImage: `url("${getURL({ url: hero.thumbnail }, PRESETS.hero)}")` }}
|
||||
key={hero.id}
|
||||
onClick={onClick}
|
||||
>
|
||||
<img
|
||||
src={getURL({ url: hero.thumbnail })}
|
||||
src={getURL({ url: hero.thumbnail }, PRESETS.hero)}
|
||||
alt={hero.thumbnail}
|
||||
onLoad={onLoad(hero.id)}
|
||||
/>
|
||||
|
|
|
@ -3,7 +3,7 @@ import * as styles from './styles.scss';
|
|||
import { IFlowState } from '~/redux/flow/reducer';
|
||||
import { getURL, getPrettyDate } from '~/utils/dom';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { URLS } from '~/constants/urls';
|
||||
import { URLS, PRESETS } from '~/constants/urls';
|
||||
import classNames from 'classnames';
|
||||
|
||||
interface IProps {
|
||||
|
@ -18,7 +18,7 @@ const FlowRecent: FC<IProps> = ({ recent, updated }) => (
|
|||
<Link key={node.id} className={styles.item} to={URLS.NODE_URL(node.id)}>
|
||||
<div
|
||||
className={classNames(styles.thumb, styles.new)}
|
||||
style={{ backgroundImage: `url("${getURL({ url: node.thumbnail })}")` }}
|
||||
style={{ backgroundImage: `url("${getURL({ url: node.thumbnail }, PRESETS.avatar)}")` }}
|
||||
/>
|
||||
|
||||
<div className={styles.info}>
|
||||
|
@ -33,7 +33,7 @@ const FlowRecent: FC<IProps> = ({ recent, updated }) => (
|
|||
<Link key={node.id} className={styles.item} to={URLS.NODE_URL(node.id)}>
|
||||
<div
|
||||
className={styles.thumb}
|
||||
style={{ backgroundImage: `url("${getURL({ url: node.thumbnail })}")` }}
|
||||
style={{ backgroundImage: `url("${getURL({ url: node.thumbnail }, PRESETS.avatar)}")` }}
|
||||
/>
|
||||
<div className={styles.info}>
|
||||
<div className={styles.title}>{node.title}</div>
|
||||
|
|
|
@ -4,6 +4,7 @@ import styles from './styles.scss';
|
|||
import { getURL } from '~/utils/dom';
|
||||
import { Icon } from '~/components/input/Icon';
|
||||
import { IUser } from '~/redux/auth/types';
|
||||
import { PRESETS } from '~/constants/urls';
|
||||
|
||||
interface IProps {
|
||||
user: Partial<IUser>;
|
||||
|
@ -14,7 +15,10 @@ const UserButton: FC<IProps> = ({ user: { username, photo }, onLogout }) => (
|
|||
<div className={styles.wrap}>
|
||||
<Group horizontal className={styles.user_button}>
|
||||
<div>{username}</div>
|
||||
<div className={styles.user_avatar} style={{ backgroundImage: `url('${getURL(photo)}')` }}>
|
||||
<div
|
||||
className={styles.user_avatar}
|
||||
style={{ backgroundImage: `url('${getURL(photo, PRESETS.avatar)}')` }}
|
||||
>
|
||||
{(!photo || !photo.id) && <Icon icon="profile" />}
|
||||
</div>
|
||||
</Group>
|
||||
|
|
|
@ -10,6 +10,7 @@ import append from 'ramda/es/append';
|
|||
import reduce from 'ramda/es/reduce';
|
||||
import { AudioPlayer } from '~/components/media/AudioPlayer';
|
||||
import classnames from 'classnames';
|
||||
import { PRESETS } from '~/constants/urls';
|
||||
|
||||
interface IProps {
|
||||
comment: IComment;
|
||||
|
@ -46,7 +47,7 @@ const CommentContent: FC<IProps> = memo(({ comment }) => {
|
|||
<div className={styles.images}>
|
||||
{groupped.image.map(file => (
|
||||
<div key={file.id}>
|
||||
<img src={getURL(file)} alt={file.name} />
|
||||
<img src={getURL(file, PRESETS['300'])} alt={file.name} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
|
|
@ -4,6 +4,7 @@ import * as styles from './styles.scss';
|
|||
import { UPLOAD_TYPES } from '~/redux/uploads/constants';
|
||||
import path from 'ramda/es/path';
|
||||
import { getURL } from '~/utils/dom';
|
||||
import { PRESETS } from '~/constants/urls';
|
||||
|
||||
interface IProps {
|
||||
node: INode;
|
||||
|
@ -19,7 +20,7 @@ const NodeAudioImageBlock: FC<IProps> = ({ node }) => {
|
|||
<div className={styles.wrap}>
|
||||
<div
|
||||
className={styles.slide}
|
||||
style={{ backgroundImage: `url("${getURL(path([0], images))}")` }}
|
||||
style={{ backgroundImage: `url("${getURL(path([0], images), PRESETS.hero)}")` }}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -1,19 +1,11 @@
|
|||
import React, {
|
||||
FC,
|
||||
useMemo,
|
||||
useState,
|
||||
useEffect,
|
||||
RefObject,
|
||||
LegacyRef,
|
||||
useRef,
|
||||
useCallback,
|
||||
} from 'react';
|
||||
import React, { FC, useMemo, useState, useEffect, useRef, useCallback } from 'react';
|
||||
import { ImageSwitcher } from '../ImageSwitcher';
|
||||
import * as styles from './styles.scss';
|
||||
import { INode } from '~/redux/types';
|
||||
import classNames from 'classnames';
|
||||
import { getImageSize } from '~/utils/dom';
|
||||
import { getURL } from '~/utils/dom';
|
||||
import { UPLOAD_TYPES } from '~/redux/uploads/constants';
|
||||
import { PRESETS } from '~/constants/urls';
|
||||
|
||||
interface IProps {
|
||||
is_loading: boolean;
|
||||
|
@ -82,7 +74,7 @@ const NodeImageBlock: FC<IProps> = ({ node, is_loading, updateLayout }) => {
|
|||
>
|
||||
<img
|
||||
className={styles.image}
|
||||
src={getImageSize(file, 'node')}
|
||||
src={getURL(file, PRESETS['1400'])}
|
||||
alt=""
|
||||
key={file.id}
|
||||
onLoad={onImageLoad(index)}
|
||||
|
|
|
@ -3,9 +3,10 @@ import { ImageSwitcher } from '../ImageSwitcher';
|
|||
import * as styles from './styles.scss';
|
||||
import { INode } from '~/redux/types';
|
||||
import classNames from 'classnames';
|
||||
import { getImageSize } from '~/utils/dom';
|
||||
import { UPLOAD_TYPES } from '~/redux/uploads/constants';
|
||||
import { NODE_SETTINGS } from '~/redux/node/constants';
|
||||
import { getURL } from '~/utils/dom';
|
||||
import { PRESETS } from '~/constants/urls';
|
||||
|
||||
interface IProps {
|
||||
is_loading: boolean;
|
||||
|
@ -206,7 +207,7 @@ const NodeImageSlideBlock: FC<IProps> = ({ node, is_loading, updateLayout }) =>
|
|||
>
|
||||
<img
|
||||
className={styles.image}
|
||||
src={getImageSize(file, 'node')}
|
||||
src={getURL(file, PRESETS['1400'])}
|
||||
alt=""
|
||||
key={file.id}
|
||||
onLoad={onImageLoad(index)}
|
||||
|
|
|
@ -2,7 +2,7 @@ import React, { FC, memo, useCallback, useState } from 'react';
|
|||
import * as styles from './styles.scss';
|
||||
import classNames from 'classnames';
|
||||
import { INode } from '~/redux/types';
|
||||
import { URLS } from '~/constants/urls';
|
||||
import { URLS, PRESETS } from '~/constants/urls';
|
||||
import { RouteComponentProps, withRouter } from 'react-router';
|
||||
import { getURL } from '~/utils/dom';
|
||||
|
||||
|
@ -22,10 +22,14 @@ const NodeRelatedItemUnconnected: FC<IProps> = memo(({ item, history }) => {
|
|||
>
|
||||
<div
|
||||
className={styles.thumb}
|
||||
style={{ backgroundImage: `url("${getURL({ url: item.thumbnail })}")` }}
|
||||
style={{ backgroundImage: `url("${getURL({ url: item.thumbnail }, PRESETS.avatar)}")` }}
|
||||
/>
|
||||
|
||||
<img src={getURL({ url: item.thumbnail })} alt="loader" onLoad={() => setIsLoaded(true)} />
|
||||
<img
|
||||
src={getURL({ url: item.thumbnail }, PRESETS.avatar)}
|
||||
alt="loader"
|
||||
onLoad={() => setIsLoaded(true)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
|
|
@ -19,4 +19,5 @@ export const PRESETS = {
|
|||
placeholder: 'placeholder',
|
||||
cover: 'cover',
|
||||
hero: 'hero',
|
||||
avatar: 'avatar',
|
||||
};
|
||||
|
|
|
@ -62,7 +62,6 @@ render(
|
|||
);
|
||||
|
||||
/*
|
||||
- better dialogs: https://codepen.io/muemue/pen/abbEMMy
|
||||
- comment editing
|
||||
- boris with comments
|
||||
- profile modal
|
||||
|
@ -71,7 +70,6 @@ render(
|
|||
- relocate files
|
||||
- import videos
|
||||
- import graffiti
|
||||
- imagecaching at backend
|
||||
- password restore
|
||||
- signup?
|
||||
- text post can also has songs http://vault48.org/post5052
|
||||
|
@ -82,6 +80,8 @@ render(
|
|||
- social integration (assimilate)
|
||||
|
||||
Done:
|
||||
|
||||
- better dialogs: https://codepen.io/muemue/pen/abbEMMy
|
||||
- imagecaching at backend
|
||||
- social integration (login, signup)
|
||||
|
||||
*/
|
||||
|
|
|
@ -72,7 +72,7 @@ export const getURL = (file: Partial<IFile>, size?: typeof PRESETS[keyof typeof
|
|||
.replace('REMOTE_OLD://', process.env.REMOTE_OLD);
|
||||
};
|
||||
|
||||
export const getImageSize = (file: IFile, size?: string): string => getURL(file);
|
||||
// export const getImageSize = (file: IFile, size?: string): string => getURL(file);
|
||||
// `${process.env.API_HOST}${image}`.replace('{size}', size);
|
||||
|
||||
export const formatText = (text: string): string =>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue