Browse Source

feature(cardview): create card component

renovate/lint-staged-8.x
Jack Mallers 7 years ago
parent
commit
2e7f30f750
  1. 16
      app/components/Channels/CardChannel.js
  2. 6
      app/components/Channels/CardChannel.scss
  3. 36
      app/reducers/channels.js
  4. 28
      app/routes/channels/components/Channels.js
  5. 11
      app/routes/channels/components/Channels.scss
  6. 4
      app/routes/channels/containers/ChannelsContainer.js

16
app/components/Channels/CardChannel.js

@ -0,0 +1,16 @@
import React from 'react'
import PropTypes from 'prop-types'
import { btc } from 'utils'
import styles from './CardChannel.scss'
const CardChannel = ({ channel }) => (
<li className={styles.channel}>
CardChannel
</li>
)
CardChannel.propTypes = {
}
export default CardChannel

6
app/components/Channels/CardChannel.scss

@ -0,0 +1,6 @@
.channel {
width: 40%;
margin: 0 5% 20px 5%;
height: 500px;
background: red;
}

36
app/reducers/channels.js

@ -21,6 +21,10 @@ export const CLOSING_CHANNEL = 'CLOSING_CHANNEL'
export const CLOSING_SUCCESSFUL = 'CLOSING_SUCCESSFUL' export const CLOSING_SUCCESSFUL = 'CLOSING_SUCCESSFUL'
export const CLOSING_FAILURE = 'CLOSING_FAILURE' export const CLOSING_FAILURE = 'CLOSING_FAILURE'
export const UPDATE_SEARCH_QUERY = 'UPDATE_SEARCH_QUERY'
export const SET_VIEW_TYPE = 'SET_VIEW_TYPE'
// ------------------------------------ // ------------------------------------
// Actions // Actions
// ------------------------------------ // ------------------------------------
@ -69,6 +73,20 @@ export function openingFailure() {
} }
} }
export function updateChannelSearchQuery(searchQuery) {
return {
type: UPDATE_SEARCH_QUERY,
searchQuery
}
}
export function setViewType(viewType) {
return {
type: SET_VIEW_TYPE,
viewType
}
}
// Send IPC event for peers // Send IPC event for peers
export const fetchChannels = () => async (dispatch) => { export const fetchChannels = () => async (dispatch) => {
dispatch(getChannels()) dispatch(getChannels())
@ -180,7 +198,11 @@ const ACTION_HANDLERS = {
[OPENING_CHANNEL]: state => ({ ...state, openingChannel: true }), [OPENING_CHANNEL]: state => ({ ...state, openingChannel: true }),
[OPENING_FAILURE]: state => ({ ...state, openingChannel: false }), [OPENING_FAILURE]: state => ({ ...state, openingChannel: false }),
[CLOSING_CHANNEL]: state => ({ ...state, closingChannel: true }) [CLOSING_CHANNEL]: state => ({ ...state, closingChannel: true }),
[UPDATE_SEARCH_QUERY]: (state, { searchQuery }) => ({ ...state, searchQuery }),
[SET_VIEW_TYPE]: (state, { viewType }) => ({ ...state, viewType })
} }
const channelsSelectors = {} const channelsSelectors = {}
@ -189,6 +211,7 @@ const channelsSelector = state => state.channels.channels
const pendingOpenChannelsSelector = state => state.channels.pendingChannels.pending_open_channels const pendingOpenChannelsSelector = state => state.channels.pendingChannels.pending_open_channels
const pendingClosedChannelsSelector = state => state.channels.pendingChannels.pending_closing_channels const pendingClosedChannelsSelector = state => state.channels.pendingChannels.pending_closing_channels
const pendingForceClosedChannelsSelector = state => state.channels.pendingChannels.pending_force_closing_channels const pendingForceClosedChannelsSelector = state => state.channels.pendingChannels.pending_force_closing_channels
const channelSearchQuerySelector = state => state.channels.searchQuery
channelsSelectors.channelModalOpen = createSelector( channelsSelectors.channelModalOpen = createSelector(
channelSelector, channelSelector,
@ -200,8 +223,11 @@ channelsSelectors.allChannels = createSelector(
pendingOpenChannelsSelector, pendingOpenChannelsSelector,
pendingClosedChannelsSelector, pendingClosedChannelsSelector,
pendingForceClosedChannelsSelector, pendingForceClosedChannelsSelector,
(channels, pendingOpenChannels, pendingClosedChannels, pendingForcedClosedChannels) => ( channelSearchQuerySelector,
[...channels, ...pendingOpenChannels, ...pendingClosedChannels, ...pendingForcedClosedChannels] (channels, pendingOpenChannels, pendingClosedChannels, pendingForcedClosedChannels, searchQuery) => (
[...channels, ...pendingOpenChannels, ...pendingClosedChannels, ...pendingForcedClosedChannels].filter(channel =>
channel.remote_pubkey.includes(searchQuery) || channel.channel_point.includes(searchQuery)
)
) )
) )
@ -227,7 +253,9 @@ const initialState = {
push_amt: '' push_amt: ''
}, },
openingChannel: false, openingChannel: false,
closingChannel: false closingChannel: false,
searchQuery: '',
viewType: 0
} }
export default function channelsReducer(state = initialState, action) { export default function channelsReducer(state = initialState, action) {

28
app/routes/channels/components/Channels.js

@ -5,6 +5,7 @@ import { FaAlignJustify, FaThLarge } from 'react-icons/lib/fa'
import { MdSearch } from 'react-icons/lib/md' import { MdSearch } from 'react-icons/lib/md'
import Channel from 'components/Channels/Channel' import Channel from 'components/Channels/Channel'
import CardChannel from 'components/Channels/CardChannel'
import ChannelForm from 'components/ChannelForm' import ChannelForm from 'components/ChannelForm'
import styles from './Channels.scss' import styles from './Channels.scss'
@ -19,8 +20,10 @@ class Channels extends Component {
render() { render() {
const { const {
channels: { channels }, channels: { channels, searchQuery, viewType },
allChannels, allChannels,
updateChannelSearchQuery,
setViewType,
closeChannelForm, closeChannelForm,
openChannelForm, openChannelForm,
@ -45,20 +48,20 @@ class Channels extends Component {
<MdSearch /> <MdSearch />
</label> </label>
<input <input
value={''} value={searchQuery}
onChange={event => console.log('event: ', event)} onChange={event => updateChannelSearchQuery(event.target.value)}
className={`${styles.text} ${styles.input}`} className={`${styles.text} ${styles.input}`}
placeholder='Search channels by funding transaction, channel id, remote public key, etc' placeholder='Search channels by funding transaction or remote public key'
type='text' type='text'
id='channelSearch' id='channelSearch'
/> />
</div> </div>
<header className={styles.header}> <header className={styles.header}>
<div className={styles.layoutsContainer}> <div className={styles.layoutsContainer}>
<span className={styles.active}> <span className={viewType === 0 && styles.active} onClick={() => setViewType(0)}>
<FaAlignJustify /> <FaAlignJustify />
</span> </span>
<span> <span className={viewType === 1 && styles.active} onClick={() => setViewType(1)}>
<FaThLarge /> <FaThLarge />
</span> </span>
</div> </div>
@ -70,9 +73,8 @@ class Channels extends Component {
</header> </header>
<div className={styles.channels}> <div className={styles.channels}>
<ul> <ul className={viewType === 1 && styles.cardsContainer}>
{ { viewType === 0 && allChannels.map((channel, index) => {
allChannels.map((channel, index) => {
return ( return (
<Channel <Channel
key={index} key={index}
@ -84,6 +86,14 @@ class Channels extends Component {
) )
}) })
} }
{ viewType === 1 && allChannels.map((channel, index) => {
return (
<CardChannel key={index}>
card channel
</CardChannel>
)
})
}
</ul> </ul>
</div> </div>
</div> </div>

11
app/routes/channels/components/Channels.scss

@ -1,9 +1,5 @@
@import '../../../variables.scss'; @import '../../../variables.scss';
.container {
}
.search { .search {
height: 75px; height: 75px;
padding: 2px 25px; padding: 2px 25px;
@ -73,4 +69,11 @@
.channels { .channels {
padding: 10px 40px 40px 40px; padding: 10px 40px 40px 40px;
.cardsContainer {
display: flex;
justify-content: center;
flex-wrap: wrap;
box-sizing: border-box;
}
} }

4
app/routes/channels/containers/ChannelsContainer.js

@ -4,6 +4,8 @@ import { connect } from 'react-redux'
import { import {
fetchChannels, fetchChannels,
openChannel, openChannel,
updateChannelSearchQuery,
setViewType,
channelsSelectors channelsSelectors
} from 'reducers/channels' } from 'reducers/channels'
@ -27,6 +29,8 @@ import Channels from '../components/Channels'
const mapDispatchToProps = { const mapDispatchToProps = {
fetchChannels, fetchChannels,
openChannel, openChannel,
updateChannelSearchQuery,
setViewType,
openChannelForm, openChannelForm,
closeChannelForm, closeChannelForm,

Loading…
Cancel
Save