From 20ebb332d6fe9f60dfd7a1776e86c04c8b992833 Mon Sep 17 00:00:00 2001 From: Walid Date: Sat, 8 Feb 2020 19:02:46 -0500 Subject: [PATCH] adds my links --- app/controllers/links_controller.rb | 9 +++++++++ client/src/actions/linkActions.js | 6 +++--- client/src/components/DDMenu.js | 11 +++++++---- client/src/components/DDMenu.scss | 2 ++ client/src/components/cliques/CliquesList.js | 2 +- client/src/components/links/LinksContainer.js | 3 ++- client/src/components/ui_components/MyLinks.js | 7 +++++++ client/src/routes.js | 1 + 8 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 client/src/components/ui_components/MyLinks.js diff --git a/app/controllers/links_controller.rb b/app/controllers/links_controller.rb index f35f7e86..f0cc5ab8 100644 --- a/app/controllers/links_controller.rb +++ b/app/controllers/links_controller.rb @@ -42,6 +42,14 @@ def link_form_details } end + def my_links + @current_page = params[:page].to_i + @page_size = 25 + @links = current_user.links.page(@current_page).per(@page_size) + @pages_count = @links.total_pages + render :index + end + # GET /links # GET /links.json def index @@ -72,6 +80,7 @@ def index # new_c_ids = c_ids.select{|c_id| clique_ids.include?(c_id)} @link_assignments = @link_assignments.where(clique_id: c_ids) end + if p_ids = params[:playlists].presence @link_assignments = PlaylistAssignment .where(playlist_id: p_ids) diff --git a/client/src/actions/linkActions.js b/client/src/actions/linkActions.js index dfe03471..1aae1133 100644 --- a/client/src/actions/linkActions.js +++ b/client/src/actions/linkActions.js @@ -1,12 +1,12 @@ import * as types from './actionTypes'; import { request, routes } from '../request'; -export const getLinks = ({ filters, page }) => { - console.log(filters); +export const getLinks = ({ filters, page, }) => { return { type: types.GET_LINKS, payload: new Promise(resolve => { - request(routes.api.links.explore, { qs: { + const url = filters.mineOnly ? routes.api.links.myLinks : routes.api.links.explore + request(url, { qs: { ...filters, users: filters.users.map(u=>u.id), cliques: filters.cliques.map(c => c.id), diff --git a/client/src/components/DDMenu.js b/client/src/components/DDMenu.js index e6a2d36b..929ab433 100644 --- a/client/src/components/DDMenu.js +++ b/client/src/components/DDMenu.js @@ -6,6 +6,8 @@ import PlaylistList from './playlists/PlaylistList'; import LinkUI from './links/LinkUI'; import styles from './DDMenu.scss'; +import MyLinks from './ui_components/MyLinks'; +import { Link } from 'react-router-dom'; class DDMenu extends Component { static propTypes = { @@ -29,10 +31,11 @@ class DDMenu extends Component { disabledTabClassName={styles.disabled} > - {['explore', 'playlists', 'player'].map( menu => {menu})} + My Digs + explore + playlists + player +
diff --git a/client/src/components/DDMenu.scss b/client/src/components/DDMenu.scss index d771c9af..7cf673a2 100644 --- a/client/src/components/DDMenu.scss +++ b/client/src/components/DDMenu.scss @@ -30,6 +30,8 @@ $background: $background-grey; } .menuItem{ padding: .5rem 1rem; + cursor: pointer; + text-decoration: none; } .tabsWrapper{ max-height: 360px; diff --git a/client/src/components/cliques/CliquesList.js b/client/src/components/cliques/CliquesList.js index 2216b9f0..479af243 100644 --- a/client/src/components/cliques/CliquesList.js +++ b/client/src/components/cliques/CliquesList.js @@ -34,7 +34,7 @@ function CliquesList(props) { ].join(' ')} key={user.id} onClick={() => hasLinks && clickUser(user)}> {user.name} - {user.link_clique_assignments_count} + {user.link_clique_assignments_count}
} } diff --git a/client/src/components/links/LinksContainer.js b/client/src/components/links/LinksContainer.js index 887b0192..52934c0a 100644 --- a/client/src/components/links/LinksContainer.js +++ b/client/src/components/links/LinksContainer.js @@ -34,6 +34,7 @@ class LinksContainer extends Component { resetFilters(props = this.props){ this.props.resetFilters({ users: props.displayMine ? [{id:props.user.id}] : [], + mineOnly: props.displayMine, }); } componentDidMount() { @@ -102,7 +103,7 @@ class LinksContainer extends Component { return

{name}

} renderIsWalid(){ - const total = this.props.pagination.total * this.props.pagination.page_size + const total = this.props.pagination.total * this.props.pagination.page_size return this.props.isWalid ?
Oops! No one digged tracks to this clique yet. When this happens, we show you all {total} founder's digs.
diff --git a/client/src/components/ui_components/MyLinks.js b/client/src/components/ui_components/MyLinks.js new file mode 100644 index 00000000..d717b9b5 --- /dev/null +++ b/client/src/components/ui_components/MyLinks.js @@ -0,0 +1,7 @@ +import React from 'react' + +const MyLinks = ({ className }) => { + return
My Digs
+} + +export default MyLinks \ No newline at end of file diff --git a/client/src/routes.js b/client/src/routes.js index 1dfcbe98..017953a4 100644 --- a/client/src/routes.js +++ b/client/src/routes.js @@ -8,6 +8,7 @@ const routes = { covers: '/api/covers', links: { explore: '/api/links.json', + myLinks: '/api/links/my_links.json', filters: '/api/filters.json', formDetails: url => `/api/link_form_details.json?url=${encodeURIComponent(url)}`, create: '/api/links.json',