Skip to content

Commit

Permalink
fix: also random friends in home page
Browse files Browse the repository at this point in the history
  • Loading branch information
Innei committed Jul 6, 2022
1 parent a2b063a commit 5f63ad5
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/components/in-page/Home/SectionNews/friend.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { shuffle } from 'lodash-es'
import type { FC } from 'react'
import { memo, useEffect, useState } from 'react'

Expand All @@ -21,13 +22,17 @@ export const FriendItem: FC<LinkModel> = memo((props) => {
export const FriendsSection: FC = memo(() => {
const [friends, setFriends] = useState<LinkModel[]>([])
useEffect(() => {
apiClient.link.getAllPaginated(1, 20).then((res) => {
apiClient.link.getAll().then((res) => {
const data = res.data as LinkModel[]
setFriends(
data.filter(
(i) =>
i.type === LinkType.Friend && i.state === LinkState.Pass && !i.hide,
),
shuffle(
data.filter(
(i) =>
i.type === LinkType.Friend &&
i.state === LinkState.Pass &&
!i.hide,
),
).slice(0, 20),
)
})
}, [])
Expand Down

0 comments on commit 5f63ad5

Please sign in to comment.