|
1 | 1 | <script> |
2 | | - import { onMount } from 'svelte'; |
| 2 | +import { onMount } from 'svelte'; |
3 | 3 |
|
4 | | - import langs from '../../routes/index.js'; |
| 4 | +import langs from '../../routes/index.js'; |
5 | 5 |
|
6 | | - import Card from './Card.svelte'; |
7 | | - import Progress from './Progress.svelte'; |
8 | | - import ScrollTop from './ScrollTop.svelte'; |
9 | | - import Styles from './Styles.svelte'; |
| 6 | +import Card from './Card.svelte'; |
| 7 | +import Progress from './Progress.svelte'; |
| 8 | +import ScrollTop from './ScrollTop.svelte'; |
10 | 9 |
|
11 | | - let owner = ''; |
12 | | - let currentOwner = ''; |
13 | | - let data; |
14 | | - let langCount; |
15 | | - let repoCount; |
16 | | - let placeholder = '[ GitHub Username ]'; |
17 | | - let done = false; |
18 | | - let url = false; |
| 10 | +let owner = ''; |
| 11 | +let currentOwner = ''; |
| 12 | +let data; |
| 13 | +let langCount; |
| 14 | +let repoCount; |
| 15 | +let placeholder = '[ GitHub Username ]'; |
| 16 | +let done = false; |
| 17 | +let url = false; |
19 | 18 |
|
20 | | - onMount(async () => { |
21 | | - const windowOwner = `${window.location.pathname.split('/')[1]}`; |
22 | | - if (windowOwner && windowOwner.length > 0) { |
23 | | - currentOwner = windowOwner; |
24 | | - owner = windowOwner; |
25 | | - url = true; |
26 | | - await submit('window'); |
27 | | - } |
28 | | - }); |
| 19 | +onMount(async () => { |
| 20 | + const windowOwner = `${window.location.pathname.split('/')[1]}`; |
| 21 | + if (windowOwner && windowOwner.length > 0) { |
| 22 | + currentOwner = windowOwner; |
| 23 | + owner = windowOwner; |
| 24 | + url = true; |
| 25 | + await submit('window'); |
| 26 | + } |
| 27 | +}); |
29 | 28 |
|
30 | | - const isDone = () => { |
31 | | - done = true; |
32 | | - }; |
| 29 | +const isDone = () => { |
| 30 | + done = true; |
| 31 | +}; |
33 | 32 |
|
34 | | - const getData = async (owner) => { |
35 | | - try { |
36 | | - const response = await langs(owner); |
37 | | - return response.data; |
38 | | - } catch (error) { |
39 | | - return error; |
40 | | - } |
41 | | - }; |
| 33 | +const getData = async (owner) => { |
| 34 | + try { |
| 35 | + const response = await langs(owner); |
| 36 | + return response.data; |
| 37 | + } catch (error) { |
| 38 | + return error; |
| 39 | + } |
| 40 | +}; |
42 | 41 |
|
43 | | - const submit = async (event) => { |
44 | | - try { |
45 | | - if (event === 'window' || !event.key || event.key === 'Enter') { |
46 | | - if (event !== 'window') { |
47 | | - event.target.blur(); |
48 | | - } |
49 | | - done = false; |
50 | | - data = undefined; |
51 | | - langCount = undefined; |
52 | | - repoCount = undefined; |
53 | | - currentOwner = owner; |
54 | | - owner = ''; |
55 | | - const collectData = []; |
56 | | - const allData = await getData(currentOwner); |
57 | | - if (allData.names) { |
58 | | - repoCount = allData.names.length; |
59 | | - } |
| 42 | +const submit = async (event) => { |
| 43 | + try { |
| 44 | + if (event === 'window' || !event.key || event.key === 'Enter') { |
| 45 | + if (event !== 'window') { |
| 46 | + event.target.blur(); |
| 47 | + } |
| 48 | + done = false; |
| 49 | + data = undefined; |
| 50 | + langCount = undefined; |
| 51 | + repoCount = undefined; |
| 52 | + currentOwner = owner; |
| 53 | + owner = ''; |
| 54 | + const collectData = []; |
| 55 | + const allData = await getData(currentOwner); |
| 56 | + if (allData.names) { |
| 57 | + repoCount = allData.names.length; |
| 58 | + } |
60 | 59 |
|
61 | | - if (allData.space) { |
62 | | - const keys = Object.keys(allData.space); |
63 | | - langCount = keys.length; |
64 | | - for (const key of keys) { |
65 | | - collectData.push({ name: key, percent: allData.space[key] }); |
66 | | - } |
67 | | - collectData.sort((a, b) => b.percent - a.percent); |
68 | | - data = collectData; |
| 60 | + if (allData.space) { |
| 61 | + const keys = Object.keys(allData.space); |
| 62 | + langCount = keys.length; |
| 63 | + for (const key of keys) { |
| 64 | + collectData.push({ name: key, percent: allData.space[key] }); |
69 | 65 | } |
| 66 | + collectData.sort((a, b) => b.percent - a.percent); |
| 67 | + data = collectData; |
70 | 68 | } |
71 | | - return true; |
72 | | - } catch (error) { |
73 | | - return error; |
74 | 69 | } |
75 | | - }; |
| 70 | + return true; |
| 71 | + } catch (error) { |
| 72 | + return error; |
| 73 | + } |
| 74 | +}; |
76 | 75 | </script> |
77 | 76 |
|
78 | 77 | <template> |
79 | | - <Styles /> |
80 | 78 | <img id="logo" src="public/assets/img/gitlang.svg" alt="GITLANG" /> |
81 | 79 | {#if !url} |
82 | 80 | <h5> |
|
89 | 87 | tabindex="0" |
90 | 88 | id="search" |
91 | 89 | type="text" |
92 | | - bind:value={owner} |
93 | | - {placeholder} |
94 | | - on:focus={() => { |
| 90 | + bind:value="{owner}" |
| 91 | + placeholder="{placeholder}" |
| 92 | + on:focus="{() => { |
95 | 93 | placeholder = ''; |
96 | | - }} |
97 | | - on:blur={() => { |
| 94 | + }}" |
| 95 | + on:blur="{() => { |
98 | 96 | placeholder = '[ GitHub Username ]'; |
99 | | - }} |
100 | | - on:keydown={submit} |
| 97 | + }}" |
| 98 | + on:keydown="{submit}" |
101 | 99 | autocorrect="off" |
102 | 100 | autocapitalize="none" |
103 | 101 | /> |
104 | 102 |
|
105 | | - <button on:click={submit}>Submit</button> |
| 103 | + <button on:click="{submit}">Submit</button> |
106 | 104 | </div> |
107 | 105 | {/if} |
108 | 106 |
|
109 | 107 | <div id="results"> |
110 | 108 | {#if currentOwner} |
111 | | - <Card {langCount} {repoCount} {currentOwner} {data} /> |
| 109 | + <Card |
| 110 | + langCount="{langCount}" |
| 111 | + repoCount="{repoCount}" |
| 112 | + currentOwner="{currentOwner}" |
| 113 | + data="{data}" |
| 114 | + /> |
112 | 115 | {/if} |
113 | 116 | {#if data} |
114 | 117 | <table> |
115 | 118 | <tbody id="tbody"> |
116 | 119 | {#if data.length > 0} |
117 | 120 | {#each data as dat, index} |
118 | | - <Progress {dat} {index} {langCount} {isDone} /> |
| 121 | + <Progress |
| 122 | + dat="{dat}" |
| 123 | + index="{index}" |
| 124 | + langCount="{langCount}" |
| 125 | + isDone="{isDone}" |
| 126 | + /> |
119 | 127 | {/each} |
120 | 128 | {:else} |
121 | 129 | <h4>User Not Found</h4> |
|
135 | 143 | </template> |
136 | 144 |
|
137 | 145 | <style> |
138 | | - #input-area { |
139 | | - padding-bottom: 20px; |
140 | | - display: flex; |
141 | | - flex-direction: column; |
142 | | - align-items: center; |
143 | | - } |
| 146 | +#input-area { |
| 147 | + padding-bottom: 20px; |
| 148 | + display: flex; |
| 149 | + flex-direction: column; |
| 150 | + align-items: center; |
| 151 | +} |
144 | 152 |
|
145 | | - #results { |
146 | | - width: 100%; |
147 | | - padding: 0 0 10px 0; |
148 | | - text-align: center; |
149 | | - display: flex; |
150 | | - flex-direction: column; |
151 | | - align-items: center; |
152 | | - } |
| 153 | +#results { |
| 154 | + width: 100%; |
| 155 | + padding: 0 0 10px 0; |
| 156 | + text-align: center; |
| 157 | + display: flex; |
| 158 | + flex-direction: column; |
| 159 | + align-items: center; |
| 160 | +} |
153 | 161 | </style> |
0 commit comments