diff --git a/frontend/src/Settings/Profiles/Release/ReleaseProfile.js b/frontend/src/Settings/Profiles/Release/ReleaseProfile.js
index 75d867954..f1b03a68f 100644
--- a/frontend/src/Settings/Profiles/Release/ReleaseProfile.js
+++ b/frontend/src/Settings/Profiles/Release/ReleaseProfile.js
@@ -9,10 +9,6 @@ import ConfirmModal from 'Components/Modal/ConfirmModal';
import EditReleaseProfileModalConnector from './EditReleaseProfileModalConnector';
import styles from './ReleaseProfile.css';
-function sortPreferred(preferred) {
- return preferred.slice().sort((a, b) => b.value - a.value);
-}
-
class ReleaseProfile extends Component {
//
@@ -22,20 +18,11 @@ class ReleaseProfile extends Component {
super(props, context);
this.state = {
- sortedPreferred: sortPreferred(props.preferred),
isEditReleaseProfileModalOpen: false,
isDeleteReleaseProfileModalOpen: false
};
}
- componentDidUpdate(prevProps) {
- const { preferred } = this.props;
-
- if (prevProps.preferred !== preferred) {
- this.setState({ sortedPreferred: sortPreferred(preferred) });
- }
- }
-
//
// Listeners
@@ -70,12 +57,12 @@ class ReleaseProfile extends Component {
id,
required,
ignored,
+ preferred,
tags,
tagList
} = this.props;
const {
- sortedPreferred,
isEditReleaseProfileModalOpen,
isDeleteReleaseProfileModalOpen
} = this.state;
@@ -126,7 +113,7 @@ class ReleaseProfile extends Component {
{
- sortedPreferred.map((item) => {
+ preferred.map((item) => {
const isPreferred = item.value >= 0;
return (
diff --git a/src/NzbDrone.Core/Profiles/Releases/ReleaseProfile.cs b/src/NzbDrone.Core/Profiles/Releases/ReleaseProfile.cs
index 962a946c9..e642ce094 100644
--- a/src/NzbDrone.Core/Profiles/Releases/ReleaseProfile.cs
+++ b/src/NzbDrone.Core/Profiles/Releases/ReleaseProfile.cs
@@ -18,4 +18,12 @@ namespace NzbDrone.Core.Profiles.Releases
Tags = new HashSet();
}
}
+
+ public class ReleaseProfilePreferredComparer : IComparer>
+ {
+ public int Compare(KeyValuePair x, KeyValuePair y)
+ {
+ return y.Value.CompareTo(x.Value);
+ }
+ }
}
diff --git a/src/NzbDrone.Core/Profiles/Releases/ReleaseProfileService.cs b/src/NzbDrone.Core/Profiles/Releases/ReleaseProfileService.cs
index 7ae1b79eb..4d79de81f 100644
--- a/src/NzbDrone.Core/Profiles/Releases/ReleaseProfileService.cs
+++ b/src/NzbDrone.Core/Profiles/Releases/ReleaseProfileService.cs
@@ -18,18 +18,24 @@ namespace NzbDrone.Core.Profiles.Releases
public class ReleaseProfileService : IReleaseProfileService
{
+ private readonly ReleaseProfilePreferredComparer _preferredComparer;
private readonly IRestrictionRepository _repo;
private readonly Logger _logger;
public ReleaseProfileService(IRestrictionRepository repo, Logger logger)
{
+ _preferredComparer = new ReleaseProfilePreferredComparer();
+
_repo = repo;
_logger = logger;
}
public List All()
{
- return _repo.All().ToList();
+ var all = _repo.All().ToList();
+ all.ForEach(r => r.Preferred.Sort(_preferredComparer));
+
+ return all;
}
public List AllForTag(int tagId)
@@ -54,11 +60,15 @@ namespace NzbDrone.Core.Profiles.Releases
public ReleaseProfile Add(ReleaseProfile restriction)
{
+ restriction.Preferred.Sort(_preferredComparer);
+
return _repo.Insert(restriction);
}
public ReleaseProfile Update(ReleaseProfile restriction)
{
+ restriction.Preferred.Sort(_preferredComparer);
+
return _repo.Update(restriction);
}
}