Skip to content

Commit

Permalink
chore(sorting): live channels are listen on top
Browse files Browse the repository at this point in the history
  • Loading branch information
zigamacele committed Oct 3, 2023
1 parent 1c5f423 commit 8d18271
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/components/Home/DisplayMyLivers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const DisplayMyLivers = () => {
}

const getLiveStatus = () => {
let tempLiveStatus = {}
let tempLiveStatus: ChromeStorageData = {}
for (const [key, value] of Object.entries(displayLivers)) {
for (let index = 0; index < data.length; index++) {
if (key === data[index]?.channel.id && data[index]?.status === 'live') {
Expand Down Expand Up @@ -108,7 +108,27 @@ const DisplayMyLivers = () => {
if (
Object.keys(tempLiveStatus).length === Object.keys(displayLivers).length
) {
setDisplayLivers(tempLiveStatus)
const output: ChromeStorageData = {}

const sorted = Object.keys(tempLiveStatus).sort((a, b) => {
if (
tempLiveStatus[a]?.status === 'live' &&
tempLiveStatus[b]?.status !== 'live'
) {
return -1
} else if (
tempLiveStatus[b]?.status === 'live' &&
tempLiveStatus[a]?.status !== 'live'
)
return 1
return 0
})

sorted.forEach((key) => {
output[key] = tempLiveStatus[key] as VTuberFromStorage
})

setDisplayLivers(output)
}
}
}
Expand Down

0 comments on commit 8d18271

Please sign in to comment.