mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
added updated nodes to flow
This commit is contained in:
parent
6f76bec2c0
commit
74cd181530
13 changed files with 128 additions and 30 deletions
|
@ -21,6 +21,7 @@ export const FlowGrid: FC<IProps> = ({
|
||||||
nodes,
|
nodes,
|
||||||
heroes,
|
heroes,
|
||||||
recent,
|
recent,
|
||||||
|
updated,
|
||||||
onSelect,
|
onSelect,
|
||||||
onChangeCellView,
|
onChangeCellView,
|
||||||
}) => (
|
}) => (
|
||||||
|
@ -30,7 +31,7 @@ export const FlowGrid: FC<IProps> = ({
|
||||||
<FlowHero heroes={heroes} />
|
<FlowHero heroes={heroes} />
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.stamp}>
|
<div className={styles.stamp}>
|
||||||
<FlowRecent recent={recent} />
|
<FlowRecent recent={recent} updated={updated} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{nodes.map(node => (
|
{nodes.map(node => (
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
$cols: $content_width / $cell;
|
$cols: $content_width / $cell;
|
||||||
|
$stamp_color: $content_bg;
|
||||||
|
|
||||||
.grid {
|
.grid {
|
||||||
padding: $gap / 2;
|
padding: $gap / 2;
|
||||||
|
@ -11,8 +12,8 @@ $cols: $content_width / $cell;
|
||||||
grid-template-rows: 50vh $cell;
|
grid-template-rows: 50vh $cell;
|
||||||
grid-auto-rows: $cell;
|
grid-auto-rows: $cell;
|
||||||
grid-auto-flow: row dense;
|
grid-auto-flow: row dense;
|
||||||
grid-column-gap: $grid_line;
|
grid-column-gap: $gap;
|
||||||
grid-row-gap: $grid_line;
|
grid-row-gap: $gap;
|
||||||
|
|
||||||
@include tablet {
|
@include tablet {
|
||||||
padding: 0 $gap;
|
padding: 0 $gap;
|
||||||
|
@ -72,10 +73,11 @@ $cols: $content_width / $cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
.stamp {
|
.stamp {
|
||||||
|
@include outer_shadow();
|
||||||
// grid-row: -1 / 3;
|
// grid-row: -1 / 3;
|
||||||
grid-row-end: span 2;
|
grid-row-end: span 2;
|
||||||
grid-column: -2 / -1;
|
grid-column: -2 / -1;
|
||||||
background: darken($content_bg, 8%);
|
background: $stamp_color;
|
||||||
border-radius: $radius;
|
border-radius: $radius;
|
||||||
padding: $gap;
|
padding: $gap;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
@ -85,4 +87,16 @@ $cols: $content_width / $cell;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: stretch;
|
align-items: stretch;
|
||||||
justify-content: stretch;
|
justify-content: stretch;
|
||||||
|
overflow: hidden;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
height: 60px;
|
||||||
|
width: 100%;
|
||||||
|
background: linear-gradient(transparentize($stamp_color, 1), $stamp_color 90%);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,45 @@
|
||||||
import React, { FC } from 'react';
|
import React, { FC } from 'react';
|
||||||
import * as styles from './styles.scss';
|
import * as styles from './styles.scss';
|
||||||
import { IFlowState } from '~/redux/flow/reducer';
|
import { IFlowState } from '~/redux/flow/reducer';
|
||||||
|
import { getURL } from '~/utils/dom';
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
|
import { URLS } from '~/constants/urls';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
recent: IFlowState['recent'];
|
recent: IFlowState['recent'];
|
||||||
|
updated: IFlowState['updated'];
|
||||||
}
|
}
|
||||||
|
|
||||||
const FlowRecent: FC<IProps> = ({ recent }) => (
|
const FlowRecent: FC<IProps> = ({ recent, updated }) => (
|
||||||
<div className={styles.grid}>
|
<div className={styles.grid}>
|
||||||
|
{updated &&
|
||||||
|
updated.slice(0, 20).map(node => (
|
||||||
|
<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 })}")` }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className={styles.info}>
|
||||||
|
<div className={styles.title}>{node.title}</div>
|
||||||
|
<div className={styles.comment}>{node.created_at}</div>
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
|
||||||
{recent &&
|
{recent &&
|
||||||
recent.slice(0, 9).map(node => (
|
recent.slice(0, 20).map(node => (
|
||||||
<div key={node.id} className={styles.item}>
|
<Link key={node.id} className={styles.item} to={URLS.NODE_URL(node.id)}>
|
||||||
<div className={styles.thumb} />
|
<div
|
||||||
<div className={styles.info}>{node.title}</div>
|
className={styles.thumb}
|
||||||
</div>
|
style={{ backgroundImage: `url("${getURL({ url: node.thumbnail })}")` }}
|
||||||
|
/>
|
||||||
|
<div className={styles.info}>
|
||||||
|
<div className={styles.title}>{node.title}</div>
|
||||||
|
<div className={styles.comment}>{node.created_at}</div>
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
.grid {
|
.grid {
|
||||||
display: grid;
|
display: flex;
|
||||||
grid-template-rows: repeat(9, 1fr);
|
|
||||||
grid-template-columns: auto;
|
|
||||||
row-gap: $grid_line;
|
|
||||||
justify-content: stretch;
|
justify-content: stretch;
|
||||||
|
flex-direction: column;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
|
||||||
& > div {
|
& > div {
|
||||||
|
@ -20,17 +18,51 @@
|
||||||
font: $font_12_regular;
|
font: $font_12_regular;
|
||||||
border-radius: $radius;
|
border-radius: $radius;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
margin-bottom: $gap;
|
||||||
|
color: white;
|
||||||
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.thumb {
|
.thumb {
|
||||||
height: 100%;
|
height: 48px;
|
||||||
width: 40px;
|
margin-right: $gap;
|
||||||
margin-right: $grid_line;
|
background: 50% 50% no-repeat/cover;
|
||||||
// padding-left: 100%;
|
border-radius: $radius;
|
||||||
background: red;
|
flex: 0 0 48px;
|
||||||
// flex:
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
&.new {
|
||||||
|
&::after {
|
||||||
|
content: ' ';
|
||||||
|
width: 12px;
|
||||||
|
height: 12px;
|
||||||
|
border-radius: 100%;
|
||||||
|
background: $red;
|
||||||
|
box-shadow: $content_bg 0 0 0 5px;
|
||||||
|
position: absolute;
|
||||||
|
right: -2px;
|
||||||
|
bottom: -2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.info {
|
.info {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.title {
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
overflow: hidden;
|
||||||
|
font: $font_16_semibold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.comment {
|
||||||
|
font: $font_12_regular;
|
||||||
|
margin-top: 4px;
|
||||||
|
opacity: 0.5;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import pick from 'ramda/es/pick';
|
||||||
import { selectUser } from '~/redux/auth/selectors';
|
import { selectUser } from '~/redux/auth/selectors';
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = state => ({
|
||||||
flow: pick(['nodes', 'heroes', 'recent'], selectFlow(state)),
|
flow: pick(['nodes', 'heroes', 'recent', 'updated'], selectFlow(state)),
|
||||||
user: pick(['role', 'id'], selectUser(state)),
|
user: pick(['role', 'id'], selectUser(state)),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ const mapDispatchToProps = {
|
||||||
type IProps = ReturnType<typeof mapStateToProps> & typeof mapDispatchToProps & {};
|
type IProps = ReturnType<typeof mapStateToProps> & typeof mapDispatchToProps & {};
|
||||||
|
|
||||||
const FlowLayoutUnconnected: FC<IProps> = ({
|
const FlowLayoutUnconnected: FC<IProps> = ({
|
||||||
flow: { nodes, heroes, recent },
|
flow: { nodes, heroes, recent, updated },
|
||||||
user,
|
user,
|
||||||
nodeLoadNode,
|
nodeLoadNode,
|
||||||
flowSetCellView,
|
flowSetCellView,
|
||||||
|
@ -29,6 +29,7 @@ const FlowLayoutUnconnected: FC<IProps> = ({
|
||||||
nodes={nodes}
|
nodes={nodes}
|
||||||
heroes={heroes}
|
heroes={heroes}
|
||||||
recent={recent}
|
recent={recent}
|
||||||
|
updated={updated}
|
||||||
onSelect={nodeLoadNode}
|
onSelect={nodeLoadNode}
|
||||||
user={user}
|
user={user}
|
||||||
onChangeCellView={flowSetCellView}
|
onChangeCellView={flowSetCellView}
|
||||||
|
|
|
@ -17,6 +17,11 @@ export const flowSetRecent = (recent: IFlowState['recent']) => ({
|
||||||
type: FLOW_ACTIONS.SET_RECENT,
|
type: FLOW_ACTIONS.SET_RECENT,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const flowSetUpdated = (updated: IFlowState['updated']) => ({
|
||||||
|
updated,
|
||||||
|
type: FLOW_ACTIONS.SET_UPDATED,
|
||||||
|
});
|
||||||
|
|
||||||
export const flowSetCellView = (id: INode['id'], flow: INode['flow']) => ({
|
export const flowSetCellView = (id: INode['id'], flow: INode['flow']) => ({
|
||||||
type: FLOW_ACTIONS.SET_CELL_VIEW,
|
type: FLOW_ACTIONS.SET_CELL_VIEW,
|
||||||
id,
|
id,
|
||||||
|
|
|
@ -5,5 +5,6 @@ export const FLOW_ACTIONS = {
|
||||||
SET_NODES: `${prefix}SET_NODES`,
|
SET_NODES: `${prefix}SET_NODES`,
|
||||||
SET_HEROES: `${prefix}SET_HEROES`,
|
SET_HEROES: `${prefix}SET_HEROES`,
|
||||||
SET_RECENT: `${prefix}SET_RECENT`,
|
SET_RECENT: `${prefix}SET_RECENT`,
|
||||||
|
SET_UPDATED: `${prefix}SET_UPDATED`,
|
||||||
SET_CELL_VIEW: `${prefix}SET_CELL_VIEW`,
|
SET_CELL_VIEW: `${prefix}SET_CELL_VIEW`,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import assocPath from 'ramda/es/assocPath';
|
import assocPath from 'ramda/es/assocPath';
|
||||||
import { FLOW_ACTIONS } from './constants';
|
import { FLOW_ACTIONS } from './constants';
|
||||||
import { flowSetNodes, flowSetHeroes, flowSetRecent } from './actions';
|
import { flowSetNodes, flowSetHeroes, flowSetRecent, flowSetUpdated } from './actions';
|
||||||
import { IFlowState } from './reducer';
|
import { IFlowState } from './reducer';
|
||||||
|
|
||||||
const setNodes = (state: IFlowState, { nodes }: ReturnType<typeof flowSetNodes>) =>
|
const setNodes = (state: IFlowState, { nodes }: ReturnType<typeof flowSetNodes>) =>
|
||||||
|
@ -12,8 +12,12 @@ const setHeroes = (state: IFlowState, { heroes }: ReturnType<typeof flowSetHeroe
|
||||||
const setRecent = (state: IFlowState, { recent }: ReturnType<typeof flowSetRecent>) =>
|
const setRecent = (state: IFlowState, { recent }: ReturnType<typeof flowSetRecent>) =>
|
||||||
assocPath(['recent'], recent, state);
|
assocPath(['recent'], recent, state);
|
||||||
|
|
||||||
|
const setUpdated = (state: IFlowState, { updated }: ReturnType<typeof flowSetUpdated>) =>
|
||||||
|
assocPath(['updated'], updated, state);
|
||||||
|
|
||||||
export const FLOW_HANDLERS = {
|
export const FLOW_HANDLERS = {
|
||||||
[FLOW_ACTIONS.SET_NODES]: setNodes,
|
[FLOW_ACTIONS.SET_NODES]: setNodes,
|
||||||
[FLOW_ACTIONS.SET_HEROES]: setHeroes,
|
[FLOW_ACTIONS.SET_HEROES]: setHeroes,
|
||||||
[FLOW_ACTIONS.SET_RECENT]: setRecent,
|
[FLOW_ACTIONS.SET_RECENT]: setRecent,
|
||||||
|
[FLOW_ACTIONS.SET_UPDATED]: setUpdated,
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,6 +7,7 @@ export type IFlowState = Readonly<{
|
||||||
nodes: INode[];
|
nodes: INode[];
|
||||||
heroes: Partial<INode>[];
|
heroes: Partial<INode>[];
|
||||||
recent: Partial<INode>[];
|
recent: Partial<INode>[];
|
||||||
|
updated: Partial<INode>[];
|
||||||
error: IError;
|
error: IError;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
|
@ -14,6 +15,7 @@ const INITIAL_STATE: IFlowState = {
|
||||||
nodes: [],
|
nodes: [],
|
||||||
heroes: [],
|
heroes: [],
|
||||||
recent: [],
|
recent: [],
|
||||||
|
updated: [],
|
||||||
is_loading: false,
|
is_loading: false,
|
||||||
error: null,
|
error: null,
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,13 @@ import { takeLatest, call, put, select } from 'redux-saga/effects';
|
||||||
import { REHYDRATE } from 'redux-persist';
|
import { REHYDRATE } from 'redux-persist';
|
||||||
import { FLOW_ACTIONS } from './constants';
|
import { FLOW_ACTIONS } from './constants';
|
||||||
import { getNodes } from '../node/api';
|
import { getNodes } from '../node/api';
|
||||||
import { flowSetNodes, flowSetCellView, flowSetHeroes, flowSetRecent } from './actions';
|
import {
|
||||||
|
flowSetNodes,
|
||||||
|
flowSetCellView,
|
||||||
|
flowSetHeroes,
|
||||||
|
flowSetRecent,
|
||||||
|
flowSetUpdated,
|
||||||
|
} from './actions';
|
||||||
import { IResultWithStatus, INode } from '../types';
|
import { IResultWithStatus, INode } from '../types';
|
||||||
import { selectFlowNodes } from './selectors';
|
import { selectFlowNodes } from './selectors';
|
||||||
import { reqWrapper } from '../auth/sagas';
|
import { reqWrapper } from '../auth/sagas';
|
||||||
|
@ -11,23 +17,26 @@ import { IFlowState } from './reducer';
|
||||||
|
|
||||||
function* onGetFlow() {
|
function* onGetFlow() {
|
||||||
const {
|
const {
|
||||||
data: { nodes = null, heroes = null, recent = null },
|
data: { nodes = null, heroes = null, recent = [], updated = [] },
|
||||||
}: IResultWithStatus<{
|
}: IResultWithStatus<{
|
||||||
nodes: IFlowState['nodes'];
|
nodes: IFlowState['nodes'];
|
||||||
heroes: IFlowState['heroes'];
|
heroes: IFlowState['heroes'];
|
||||||
recent: IFlowState['recent'];
|
recent: IFlowState['recent'];
|
||||||
}> = yield call(getNodes, {});
|
updated: IFlowState['updated'];
|
||||||
|
}> = yield call(reqWrapper, getNodes, {});
|
||||||
|
|
||||||
if (!nodes || !nodes.length) {
|
if (!nodes || !nodes.length) {
|
||||||
yield put(flowSetNodes([]));
|
yield put(flowSetNodes([]));
|
||||||
yield put(flowSetHeroes([]));
|
yield put(flowSetHeroes([]));
|
||||||
yield put(flowSetRecent([]));
|
yield put(flowSetRecent([]));
|
||||||
|
yield put(flowSetUpdated([]));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
yield put(flowSetNodes(nodes));
|
yield put(flowSetNodes(nodes));
|
||||||
yield put(flowSetHeroes(heroes));
|
yield put(flowSetHeroes(heroes));
|
||||||
yield put(flowSetRecent(recent));
|
yield put(flowSetRecent(recent));
|
||||||
|
yield put(flowSetUpdated(updated));
|
||||||
}
|
}
|
||||||
|
|
||||||
function* onSetCellView({ id, flow }: ReturnType<typeof flowSetCellView>) {
|
function* onSetCellView({ id, flow }: ReturnType<typeof flowSetCellView>) {
|
||||||
|
|
|
@ -19,11 +19,13 @@ export const postNode = ({
|
||||||
|
|
||||||
export const getNodes = ({
|
export const getNodes = ({
|
||||||
skip = 0,
|
skip = 0,
|
||||||
|
access,
|
||||||
}: {
|
}: {
|
||||||
skip?: number;
|
skip?: number;
|
||||||
|
access: string;
|
||||||
}): Promise<IResultWithStatus<{ nodes: INode[] }>> =>
|
}): Promise<IResultWithStatus<{ nodes: INode[] }>> =>
|
||||||
api
|
api
|
||||||
.get(API.NODE.GET, { params: { skip } })
|
.get(API.NODE.GET, configWithToken(access, { params: { skip } }))
|
||||||
.then(resultMiddleware)
|
.then(resultMiddleware)
|
||||||
.catch(errorMiddleware);
|
.catch(errorMiddleware);
|
||||||
|
|
||||||
|
|
|
@ -129,8 +129,9 @@ export interface INode {
|
||||||
|
|
||||||
tags: ITag[];
|
tags: ITag[];
|
||||||
|
|
||||||
createdAt?: string;
|
created_at?: string;
|
||||||
updatedAt?: string;
|
updated_at?: string;
|
||||||
|
commented_at?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IComment {
|
export interface IComment {
|
||||||
|
|
|
@ -8,7 +8,7 @@ $spc: $gap * 2;
|
||||||
$comment_height: 72px;
|
$comment_height: 72px;
|
||||||
$bar_height: 64px;
|
$bar_height: 64px;
|
||||||
|
|
||||||
$radius: 8px;
|
$radius: 2px;
|
||||||
$cell_radius: $radius;
|
$cell_radius: $radius;
|
||||||
$panel_radius: $radius;
|
$panel_radius: $radius;
|
||||||
$input_radius: $radius;
|
$input_radius: $radius;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue