Skip to content

Commit

Permalink
Attributes add to filter by click
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavAndreasson committed Jan 1, 2024
1 parent fed7589 commit d0be683
Show file tree
Hide file tree
Showing 26 changed files with 193 additions and 83 deletions.
8 changes: 4 additions & 4 deletions frontend/src/actions/processActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export const updateSearch = query => ({
query,
})

export const FILTER_YEAR = "FILTER_YEAR"
export const filterYear = year => ({
type: FILTER_YEAR,
year,
export const ADD_FILTER = "ADD_FILTER"
export const addFilter = filter => ({
type: ADD_FILTER,
filter,
})
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { Fragment } from "react"
import Artist from "Components/Artist"

const Artists = ({ artists }) =>
artists &&
artists.map((artist, index) => (
const Artists = ({ value }) =>
value &&
value.map((artist, index) => (
<Fragment key={artist.artist.id}>
<Artist artist={artist.artist} />
{index < artists.length - 1 && " " + artist.delimiter + " "}
{index < value.length - 1 && " " + artist.delimiter + " "}
</Fragment>
))
export default Artists
File renamed without changes.
28 changes: 28 additions & 0 deletions frontend/src/components/Attributes/Formats/Formats.component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { Fragment } from "react"
import { useTranslation } from "react-i18next"
import "./Formats.scss"

const Formats = ({ value, filterFormat }) => {
const { t, i18n } = useTranslation()
return value
? value
.filter(format => format.name !== "All-Media")
.map((format, index) => (
<Fragment key={index}>
{(index && ", ") || null}
<span
className="format"
onClick={e => {
e.stopPropagation()
filterFormat(format)
}}
key={index}
>
{(format.qty > 1 ? format.qty + "x" : "") + t("format." + format.name, format.name)}
</span>
</Fragment>
))
: null
}

export default Formats
11 changes: 11 additions & 0 deletions frontend/src/components/Attributes/Formats/Formats.container.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { connect } from "react-redux"
import { addFilter } from "Actions"
import Formats from "./Formats.component"

const mapDispatchToProps = dispatch => ({
filterFormat: format => {
dispatch(addFilter({ attribute: "formats", compare: "seq", value: format.name }))
},
})

export default connect(null, mapDispatchToProps)(Formats)
4 changes: 4 additions & 0 deletions frontend/src/components/Attributes/Formats/Formats.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.format {
color: #0000aa;
cursor: pointer;
}
1 change: 1 addition & 0 deletions frontend/src/components/Attributes/Formats/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "./Formats.container"
23 changes: 23 additions & 0 deletions frontend/src/components/Attributes/Genres/Genres.component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React, { Fragment } from "react"
import "./Genres.scss"

const Genres = ({ value, filterGenre }) =>
value
? value.map((genre, index) => (
<Fragment key={index}>
{(index && ", ") || null}
<span
className="genre"
onClick={e => {
e.stopPropagation()
filterGenre(genre)
}}
key={index}
>
{genre}
</span>
</Fragment>
))
: null

export default Genres
11 changes: 11 additions & 0 deletions frontend/src/components/Attributes/Genres/Genres.container.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { connect } from "react-redux"
import { addFilter } from "Actions"
import Genres from "./Genres.component"

const mapDispatchToProps = dispatch => ({
filterGenre: genre => {
dispatch(addFilter({ attribute: "genres", compare: "seq", value: genre }))
},
})

export default connect(null, mapDispatchToProps)(Genres)
4 changes: 4 additions & 0 deletions frontend/src/components/Attributes/Genres/Genres.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.genre {
color: #0000aa;
cursor: pointer;
}
1 change: 1 addition & 0 deletions frontend/src/components/Attributes/Genres/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "./Genres.container"
5 changes: 5 additions & 0 deletions frontend/src/components/Attributes/Price/Price.component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from "react"

const Price = ({ value, rate }) => <>{value && (value * rate).toFixed(2)}</>

export default Price
8 changes: 8 additions & 0 deletions frontend/src/components/Attributes/Price/Price.container.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { connect } from "react-redux"
import Price from "./Price.component"

const mapStateToProps = state => ({
rate: state.collection.rate,
})

export default connect(mapStateToProps)(Price)
1 change: 1 addition & 0 deletions frontend/src/components/Attributes/Price/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "./Price.container"
17 changes: 17 additions & 0 deletions frontend/src/components/Attributes/Year/Year.component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from "react"
import "./Year.scss"

const Year = ({ value, filterYear }) =>
value ? (
<span
className="year"
onClick={e => {
e.stopPropagation()
filterYear(value)
}}
>
{value}
</span>
) : null

export default Year
11 changes: 11 additions & 0 deletions frontend/src/components/Attributes/Year/Year.container.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { connect } from "react-redux"
import { addFilter } from "Actions"
import Year from "./Year.component"

const mapDispatchToProps = dispatch => ({
filterYear: year => {
dispatch(addFilter({ attribute: "year", compare: "eq", value: year }))
},
})

export default connect(null, mapDispatchToProps)(Year)
4 changes: 4 additions & 0 deletions frontend/src/components/Attributes/Year/Year.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.year {
color: #0000aa;
cursor: pointer;
}
1 change: 1 addition & 0 deletions frontend/src/components/Attributes/Year/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "./Year.container"
5 changes: 5 additions & 0 deletions frontend/src/components/Attributes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export { default as Artists } from "./Artists"
export { default as Formats } from "./Formats"
export { default as Genres } from "./Genres"
export { default as Price } from "./Price"
export { default as Year } from "./Year"
52 changes: 17 additions & 35 deletions frontend/src/components/Collection/Record/Record.component.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import React from "react"
import { useTranslation } from "react-i18next"
import LazyLoad from "react-lazyload"
import Artists from "Components/Artists"
import { Artists, Formats, Genres, Price, Year } from "Components/Attributes"
import "./Record.scss"

const Record = ({ rec, gridView, gridColumns, rate, handleClick, handleYearClick }) => {
const { t, i18n } = useTranslation()
const Record = ({ rec, gridView, gridColumns, handleClick }) => {
const attributes = {
artists: Artists,
formats: Formats,
genres: Genres,
price: Price,
year: Year,
}
const artists = rec.artists
.map(
(artist, index) =>
Expand All @@ -29,37 +34,14 @@ const Record = ({ rec, gridView, gridColumns, rate, handleClick, handleYearClick
</LazyLoad>
</div>
{gridColumns &&
gridColumns.map(column => (
<div className={`record-${column}`} key={column}>
{column == "artist" ? (
<Artists artists={rec.artists} />
) : column == "price" ? (
rec.price && (rec.price * rate).toFixed(2)
) : column == "year" ? (
rec.year ? (
<span
className="year"
onClick={e => {
e.stopPropagation()
handleYearClick(rec.year)
}}
>
{rec.year}
</span>
) : null
) : column == "formats" ? (
rec.formats &&
rec.formats
.filter(f => f.name !== "All-Media")
.map(f => (f.qty > 1 ? f.qty + "x" : "") + t("format." + f.name, f.name))
.join(", ")
) : column == "genres" ? (
rec.genres && rec.genres.join(", ")
) : (
column in rec && rec[column]
)}
</div>
))}
gridColumns.map(column => {
const Attribute = attributes[column]
return (
<div className={`record-${column}`} key={column}>
{Attribute ? <Attribute value={rec[column]} /> : column in rec && rec[column]}
</div>
)
})}
</div>
) : (
<div className={`record ${format_classes}`} onClick={() => handleClick(rec)}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import { connect } from "react-redux"
import { showRecord, filterYear } from "Actions"
import { showRecord } from "Actions"
import Record from "./Record.component"

const mapStateToProps = state => ({
gridView: state.ui.gridView,
gridColumns: state.ui.gridColumns,
rate: state.collection.rate,
})

const mapDispatchToProps = dispatch => ({
handleClick: rec => {
dispatch(showRecord(rec))
},
handleYearClick: year => {
dispatch(filterYear(year))
},
})

export default connect(mapStateToProps, mapDispatchToProps)(Record)
28 changes: 14 additions & 14 deletions frontend/src/components/RecordInfo/RecordInfo.component.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useEffect } from "react"
import { useTranslation } from "react-i18next"
import Popup from "Components/Popup"
import Artists from "Components/Artists"
import { Artists, Formats, Genres, Price, Year } from "Components/Attributes"
import Listen from "./Listen"
import "./RecordInfo.scss"

Expand All @@ -11,11 +10,9 @@ const RecordInfo = ({
rate,
currency,
updateRecord,
handleYearClick,
handleListenClick,
hideRecord,
}) => {
const { t, i18n } = useTranslation()
useEffect(() => {
if (rec) {
let threeMonthsAgo = new Date()
Expand All @@ -40,27 +37,30 @@ const RecordInfo = ({
<div className={"record-info"}>
<img className="cover" src={rec.cover} />
<div className="artists">
<Artists artists={rec.artists} />
<Artists value={rec.artists} />
</div>
<div className="left">
{rec.formats && (
<div className="formats">
{rec.formats
.filter(f => f.name !== "All-Media")
.map(f => (f.qty > 1 ? f.qty + "x" : "") + t("format." + f.name, f.name))
.join(", ")}
<Formats value={rec.formats} />
</div>
)}
{(rec.year && (
<div className="year" onClick={() => handleYearClick(rec.year)}>
{rec.year}
<div className="year">
<Year value={rec.year} />
</div>
)) ||
null}
{rec.genres && <div className="genres">{rec.genres.join(", ")}</div>}
{rec.genres && (
<div className="genres">
<Genres value={rec.genres} />
</div>
)}
{rec.price && rate && (
<div className="price">
{"(" + (rec.price * rate).toFixed(2) + " " + currency + ")"}
{"("}
<Price value={rec.price} />
{" " + currency + ")"}
</div>
)}
<div className="tracks">
Expand All @@ -71,7 +71,7 @@ const RecordInfo = ({
{track.artists && (
<>
{" ("}
<Artists artists={track.artists} />
<Artists value={track.artists} />
{")"}
</>
)}
Expand Down
5 changes: 1 addition & 4 deletions frontend/src/components/RecordInfo/RecordInfo.container.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { connect } from "react-redux"
import { updateRecord, filterYear, showListen, hideRecord } from "Actions"
import { updateRecord, showListen, hideRecord } from "Actions"
import { selectActiveRecord } from "Selectors"
import RecordInfo from "./RecordInfo.component"

Expand All @@ -14,9 +14,6 @@ const mapDispatchToProps = dispatch => ({
updateRecord: record => {
dispatch(updateRecord(record))
},
handleYearClick: year => {
dispatch(filterYear(year))
},
handleListenClick: listen => {
dispatch(showListen(listen))
},
Expand Down
5 changes: 0 additions & 5 deletions frontend/src/reducers/artistReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
VIEW_ARTIST_COLLECTION,
TOGGLE_VIEW_ARTIST_COLLECTION,
RECEIVE_RECORD,
FILTER_YEAR,
} from "Actions"

function artist(
Expand Down Expand Up @@ -68,10 +67,6 @@ function artist(
return Object.assign({}, state, {
viewArtistCollection: !state.viewArtistCollection,
})
case FILTER_YEAR:
return Object.assign({}, state, {
activeRecord: null,
})
default:
return state
}
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/reducers/collectionReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
SHOW_ARTIST,
SET_CURRENCY,
RECEIVE_RATE,
ADD_FILTER,
} from "Actions"

function collection(
Expand Down Expand Up @@ -84,6 +85,10 @@ function collection(
return Object.assign({}, state, {
rate: action.rate.currency == state.currency ? action.rate.rate : state.rate,
})
case ADD_FILTER:
return Object.assign({}, state, {
activeRecord: null,
})
default:
return state
}
Expand Down
Loading

0 comments on commit d0be683

Please sign in to comment.