Skip to content

Commit dd81663

Browse files
committed
feat(main-placeholder): update text, add authToken note
1 parent c01038c commit dd81663

4 files changed

Lines changed: 48 additions & 16 deletions

File tree

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,41 @@
11
<template>
2-
<div>
3-
<b>No repositories added yet.</b>
4-
<p>
5-
To&nbsp;add a&nbsp;repository manually, use the &laquo;Add GitHub repo&raquo; button above and enter it's owner and name.
6-
</p>
7-
<p>
8-
Alternatively, visit &laquo;Settings&raquo; to&nbsp;add your token and then press &laquo;Add GitHub repo&raquo;,
9-
where you could selectively choose repositories to&nbsp;add.
10-
</p>
2+
<div class="main-placeholder">
3+
<header class="main-placeholder__header">
4+
No repositories added yet
5+
</header>
6+
To add a repository, use the <b>Add GitHub repo</b> button and enter its owner and name.
7+
<div v-if="!settings.authToken" class="main-placeholder__token-note">
8+
<header>
9+
No GitHub API token
10+
</header>
11+
Without a token you only have 50 requests per hour.
12+
<p>
13+
Go to <b>Settings</b> and paste your token there — it takes <i>less than a minute</i> and will greatly simplify working with the service.
14+
</p>
15+
<p>
16+
Once added, you can selectively choose which repositories to track and enjoy the full 5000 requests/hour limit, and get access to your private repositories.
17+
</p>
18+
</div>
1119
</div>
1220
</template>
21+
<script setup lang="ts">
22+
import { useSettingsStore } from "@/store/settings";
23+
24+
const { settings } = useSettingsStore();
25+
</script>
26+
<style lang="scss">
27+
.main-placeholder {
28+
font-size: 1.25rem;
29+
line-height: 1.3;
30+
header {
31+
margin-bottom: 1rem;
32+
font-weight: bold;
33+
}
34+
p {
35+
margin-block: .5rem;
36+
}
37+
&__token-note {
38+
margin-block: 2rem;
39+
}
40+
}
41+
</style>

src/components/modals/settings-modal.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function closeModal(): void {
8787
close();
8888
}
8989
90-
const { settings } = useSettingsStore();
90+
const { settings, setSettings } = useSettingsStore();
9191
const form = reactive(deepCopy(settings.value));
9292
watch(settings, (value) => { Object.assign(form, value); }, { deep: true });
9393
watch(() => settings.value.authToken, setAuthToken);
@@ -105,8 +105,8 @@ async function setUsername(): Promise<void> {
105105
if (user) form.username = user.login;
106106
}
107107
async function update(): Promise<void> {
108-
if (form.authToken && !form.username) await setUsername();
109-
settings.value = { ...form };
108+
if (!form.username && form.authToken) await setUsername();
109+
setSettings(form);
110110
closeModal();
111111
}
112112
</script>

src/service/octokit.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,15 @@ const { settings } = useSettingsStore();
2222
let octokit: Octokit;
2323
export const rateLimit = ref("-");
2424

25-
setAuthToken(settings.value.authToken);
26-
2725
export async function setAuthToken(authToken: string | null): Promise<void> {
28-
settings.value.authToken = authToken ?? "";
2926
octokit = new Octokit({ auth: authToken });
3027
octokit.hook.after("request", (response) => {
3128
const limitRemaining = response.headers["x-ratelimit-remaining"];
3229
if (limitRemaining) { rateLimit.value = limitRemaining; }
3330
});
3431
await fetchRateLimit();
3532
}
33+
setAuthToken(settings.value.authToken);
3634

3735
export function fetch(url: Route, options: RequestParameters = {}): Promise<any> {
3836
const NO_CACHE_LIMIT = 4000;

src/store/settings.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { readonly } from "vue";
12
import { createGlobalState, useLocalStorage } from "@vueuse/core";
23
import { useRegisterSW } from "virtual:pwa-register/vue";
34

@@ -30,6 +31,9 @@ export const useSettingsStore = createGlobalState(() => {
3031
Object.assign(settings.value, newSettings);
3132
}
3233

34+
function setSettings(payload: Partial<SettingsStore>): void {
35+
Object.assign(settings.value, payload);
36+
}
3337
function nextTheme(): void {
3438
const themes = ["github", "aqua", "cream", "mint", "rose", "departure"] as const satisfies readonly Theme[];
3539
const index = themes.indexOf(settings.value.theme);
@@ -38,8 +42,9 @@ export const useSettingsStore = createGlobalState(() => {
3842
}
3943

4044
return {
41-
settings,
45+
settings: readonly(settings),
4246
needRefresh,
47+
setSettings,
4348
updateServiceWorker,
4449
importSettings,
4550
nextTheme

0 commit comments

Comments
 (0)