11<script lang="ts" setup>
2- import { useStorage } from ' @vueuse/core '
2+ import { ref , onMounted } from ' vue '
33
4- const contributors = useStorage <any []>(' contributors ' , [])
4+ const contributors = ref <any []>([])
55
66const fromRepo = (repo : string ) =>
77 fetch (` https://api.github.com/repos/tweakphp/${repo }/contributors ` )
@@ -16,30 +16,29 @@ const getContributors = async () => {
1616 fromRepo (' .github' ),
1717 ])
1818
19- contributors .value = users .reduce ((acc , data = []) => {
20- if (! Array .isArray (data )) {
21- return acc
22- }
23-
24- return [... acc , ... data .filter (i => i .login )]
25- }, []).reduce ((acc , user ) => {
26- const existingUser = acc .find (u => u .id === user .id )
27-
28- if (existingUser ) {
29- existingUser .contributions += user .contributions
30- return acc
31- }
32-
33- return [... acc , {
34- id: user .id ,
35- username: user .login ,
36- contributions: user .contributions ,
37- avatar_url: user .avatar_url
38- }]
39- }, [])
19+ contributors .value = users
20+ .reduce ((acc , data = []) => {
21+ if (! Array .isArray (data )) return acc
22+ return [... acc , ... data .filter (i => i .login )]
23+ }, [])
24+ .reduce ((acc , user ) => {
25+ const existingUser = acc .find (u => u .id === user .id )
26+ if (existingUser ) {
27+ existingUser .contributions += user .contributions
28+ return acc
29+ }
30+ return [... acc , {
31+ id: user .id ,
32+ username: user .login ,
33+ contributions: user .contributions ,
34+ avatar_url: user .avatar_url
35+ }]
36+ }, [])
4037}
4138
42- getContributors ()
39+ onMounted (() => {
40+ getContributors ()
41+ })
4342 </script >
4443
4544<template >
0 commit comments