|
@@ -2,12 +2,6 @@ import { useEffect, useState } from 'react'
|
|
|
import { getJSON } from '../../../infrastructure/fetch-json'
|
|
import { getJSON } from '../../../infrastructure/fetch-json'
|
|
|
import useAbortController from '../../../shared/hooks/use-abort-controller'
|
|
import useAbortController from '../../../shared/hooks/use-abort-controller'
|
|
|
|
|
|
|
|
-const contactCollator = new Intl.Collator('en')
|
|
|
|
|
-
|
|
|
|
|
-const alphabetical = (a, b) =>
|
|
|
|
|
- contactCollator.compare(a.name, b.name) ||
|
|
|
|
|
- contactCollator.compare(a.email, b.email)
|
|
|
|
|
-
|
|
|
|
|
export function useUserContacts() {
|
|
export function useUserContacts() {
|
|
|
const [loading, setLoading] = useState(true)
|
|
const [loading, setLoading] = useState(true)
|
|
|
const [data, setData] = useState(null)
|
|
const [data, setData] = useState(null)
|
|
@@ -18,7 +12,7 @@ export function useUserContacts() {
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
getJSON('/user/contacts', { signal })
|
|
getJSON('/user/contacts', { signal })
|
|
|
.then(data => {
|
|
.then(data => {
|
|
|
- setData(data.contacts.map(buildContact).sort(alphabetical))
|
|
|
|
|
|
|
+ setData(data.contacts.map(buildContact))
|
|
|
})
|
|
})
|
|
|
.catch(error => setError(error))
|
|
.catch(error => setError(error))
|
|
|
.finally(() => setLoading(false))
|
|
.finally(() => setLoading(false))
|