Skip to content
This repository was archived by the owner on Feb 15, 2026. It is now read-only.

Commit 8e1f05d

Browse files
committed
fix: push active subscription to the top
1 parent b4a648c commit 8e1f05d

1 file changed

Lines changed: 32 additions & 19 deletions

File tree

  • src/components/UserProfile/UserSettings/UserNotificationSettings/UserNotificationsWebPush

src/components/UserProfile/UserSettings/UserNotificationSettings/UserNotificationsWebPush/index.tsx

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import type { UserSettingsNotificationsResponse } from '@server/interfaces/api/u
2323
import axios from 'axios';
2424
import { Form, Formik } from 'formik';
2525
import { useRouter } from 'next/router';
26-
import { useEffect, useState } from 'react';
26+
import { useEffect, useMemo, useState } from 'react';
2727
import { defineMessages, useIntl } from 'react-intl';
2828
import { useToasts } from 'react-toast-notifications';
2929
import useSWR, { mutate } from 'swr';
@@ -170,6 +170,25 @@ const UserWebPushSettings = () => {
170170
getSubscriptionEndpoint();
171171
}, [webPushEnabled]);
172172

173+
const sortedDevices = useMemo(() => {
174+
if (!dataDevices || !subEndpoint) {
175+
return dataDevices;
176+
}
177+
178+
return [...dataDevices].sort((a, b) => {
179+
if (a.endpoint === subEndpoint) {
180+
return -1;
181+
}
182+
if (b.endpoint === subEndpoint) {
183+
return 1;
184+
}
185+
186+
const dateA = a.createdAt ? new Date(a.createdAt).getTime() : 0;
187+
const dateB = b.createdAt ? new Date(b.createdAt).getTime() : 0;
188+
return dateB - dateA;
189+
});
190+
}, [dataDevices, subEndpoint]);
191+
173192
if (!data && !error) {
174193
return <LoadingSpinner />;
175194
}
@@ -286,24 +305,18 @@ const UserWebPushSettings = () => {
286305
{intl.formatMessage(messages.managedevices)}
287306
</h3>
288307
<div className="section">
289-
{dataDevices?.length ? (
290-
dataDevices
291-
?.sort((a, b) => {
292-
const dateA = a.createdAt ? new Date(a.createdAt).getTime() : 0;
293-
const dateB = b.createdAt ? new Date(b.createdAt).getTime() : 0;
294-
return dateB - dateA;
295-
})
296-
.map((device) => (
297-
<div className="py-2" key={`device-list-${device.endpoint}`}>
298-
<DeviceItem
299-
deletePushSubscriptionFromBackend={
300-
deletePushSubscriptionFromBackend
301-
}
302-
device={device}
303-
subEndpoint={subEndpoint}
304-
/>
305-
</div>
306-
))
308+
{sortedDevices?.length ? (
309+
sortedDevices.map((device) => (
310+
<div className="py-2" key={`device-list-${device.endpoint}`}>
311+
<DeviceItem
312+
deletePushSubscriptionFromBackend={
313+
deletePushSubscriptionFromBackend
314+
}
315+
device={device}
316+
subEndpoint={subEndpoint}
317+
/>
318+
</div>
319+
))
307320
) : (
308321
<>
309322
<Alert

0 commit comments

Comments
 (0)