@@ -78,14 +78,9 @@ const EditableSubscriptionsCell: React.FC<EditableSubscriptionsCellProps> = ({
78
78
79
79
// Get sorted subjects for dropdown display
80
80
const sortedSubjects = useMemo ( ( ) => {
81
- return [ ...allSubjects ] . sort ( ( a , b ) => {
82
- // First sort by archived status (unarchived first)
83
- if ( a . archived !== b . archived ) {
84
- return a . archived ? 1 : - 1 ;
85
- }
86
- // Then sort by ID
87
- return a . id - b . id ;
88
- } ) ;
81
+ return [ ...allSubjects ]
82
+ . filter ( ( subject ) => ! subject . archived ) // Filter out archived subjects
83
+ . sort ( ( a , b ) => a . id - b . id ) ; // Now we only need to sort by ID since all subjects are unarchived
89
84
} , [ allSubjects ] ) ;
90
85
91
86
// Define saveSubscriptions with useCallback so it can be used in dependency arrays
@@ -113,8 +108,14 @@ const EditableSubscriptionsCell: React.FC<EditableSubscriptionsCellProps> = ({
113
108
// Initialize selected subjects from current mailing lists
114
109
useEffect ( ( ) => {
115
110
if ( ! isSaving ) {
116
- setSelectedSubjectIds ( mailingLists . map ( ( list ) => list . subjectId ) ) ;
117
- setLocalMailingLists ( mailingLists ) ;
111
+ setSelectedSubjectIds (
112
+ mailingLists
113
+ . filter ( ( list ) => ! list . subject . archived )
114
+ . map ( ( list ) => list . subjectId )
115
+ ) ;
116
+ setLocalMailingLists (
117
+ mailingLists . filter ( ( list ) => ! list . subject . archived )
118
+ ) ;
118
119
}
119
120
} , [ mailingLists , isSaving ] ) ;
120
121
@@ -125,12 +126,12 @@ const EditableSubscriptionsCell: React.FC<EditableSubscriptionsCellProps> = ({
125
126
. map ( ( id ) => {
126
127
// Try to find existing mailing list first
127
128
const existingList = mailingLists . find ( ( list ) => list . subjectId === id ) ;
128
- if ( existingList ) return existingList ;
129
+ if ( existingList && ! existingList . subject . archived ) return existingList ;
129
130
130
131
// If not, create a new one based on the subject from our full subjects list
131
132
const subject = subjectsById [ id ] ;
132
133
133
- if ( ! subject ) return null ;
134
+ if ( ! subject || subject . archived ) return null ;
134
135
135
136
return {
136
137
subjectId : subject . id ,
@@ -139,15 +140,10 @@ const EditableSubscriptionsCell: React.FC<EditableSubscriptionsCellProps> = ({
139
140
} )
140
141
. filter ( Boolean ) as MailingList [ ] ;
141
142
142
- // Sort the new mailing lists by archived status and ID
143
- const sortedMailingLists = [ ...newMailingListsUnsorted ] . sort ( ( a , b ) => {
144
- // First sort by archived status (unarchived first)
145
- if ( a . subject . archived !== b . subject . archived ) {
146
- return a . subject . archived ? 1 : - 1 ;
147
- }
148
- // Then sort by ID
149
- return a . subjectId - b . subjectId ;
150
- } ) ;
143
+ // Sort the new mailing lists by ID
144
+ const sortedMailingLists = [ ...newMailingListsUnsorted ] . sort (
145
+ ( a , b ) => a . subjectId - b . subjectId
146
+ ) ;
151
147
152
148
setLocalMailingLists ( sortedMailingLists ) ;
153
149
} , [ selectedSubjectIds , mailingLists , subjectsById ] ) ;
0 commit comments