Skip to content

Commit f0f2f7a

Browse files
committed
Move back button to settings
1 parent 16e0ab5 commit f0f2f7a

File tree

6 files changed

+97
-43
lines changed

6 files changed

+97
-43
lines changed

src/assets/img/icon.png

34.3 KB
Loading

src/components/AppButton.vue

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
<script lang="ts" setup>
22
interface Props {
33
loading?: boolean
4+
paddingless?: boolean
5+
square?: boolean
46
}
57
interface Emits {
68
(name: 'click', event: MouseEvent): void
79
}
810
911
const props = withDefaults(defineProps<Props>(), {
1012
loading: false,
13+
paddingless: false,
14+
square: false,
1115
})
1216
const emit = defineEmits<Emits>()
1317
@@ -23,7 +27,11 @@ function handleClick(e: MouseEvent) {
2327
<button
2428
:disabled="loading || undefined"
2529
class="button"
26-
:class="{ 'button-loading': loading }"
30+
:class="{
31+
'button-loading': loading,
32+
'button-paddingless': paddingless,
33+
'button-square': square,
34+
}"
2735
@click="handleClick"
2836
>
2937
<div
@@ -53,6 +61,19 @@ function handleClick(e: MouseEvent) {
5361
color: var(--white);
5462
border-radius: 8px;
5563
@include text-outline();
64+
vertical-align: middle;
65+
66+
&-paddingless, &-square {
67+
padding: 0px;
68+
}
69+
70+
&-square {
71+
display: inline-flex;
72+
height: 35px;
73+
width: 35px;
74+
align-items: center;
75+
justify-content: center;
76+
}
5677
5778
&-loading {
5879
.button-content {

src/components/AppSidebar.vue

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,26 @@
11
<script lang="ts" setup>
2-
import { exit } from '@tauri-apps/api/process'
2+
import { open } from '@tauri-apps/api/shell'
33
import { useKey } from '../composables/useKey'
4-
import { Page } from '../constants'
4+
import { Page, REPO_LINK } from '../constants'
55
import { AppStorage } from '../storage'
66
import { useStore } from '../stores/store'
77
import { Icons } from './Icons'
88
import SidebarButton from './SidebarButton.vue'
99
1010
const store = useStore()
11-
12-
const accessToken = AppStorage.asComputed('accessToken')
13-
14-
function handleBack() {
15-
let page = Page.Home
16-
17-
if (accessToken.value == null)
18-
page = Page.Landing
19-
20-
store.setPage(page)
21-
}
22-
23-
useKey('esc', handleBack, { source: () => store.currentPage === Page.Settings })
2411
</script>
2512

2613
<template>
2714
<nav class="nav">
2815
<div class="upper">
2916
<SidebarButton
30-
title="Back to home page"
31-
:disabled="store.currentPage !== Page.Settings"
32-
@click="handleBack"
17+
title="Go to Gitification repository"
18+
@click="open(REPO_LINK)"
3319
>
34-
<Icons.ChevronLeft />
20+
<img
21+
style="width: 100%"
22+
src="/src/assets/img/icon.png"
23+
>
3524
</SidebarButton>
3625
</div>
3726
<div class="lower">
@@ -70,6 +59,7 @@ useKey('esc', handleBack, { source: () => store.currentPage === Page.Settings })
7059
flex-wrap: nowrap;
7160
padding: 10px;
7261
background-color: var(--sidebar-bg);
62+
width: 57px;
7363
7464
.sync-icon-spin {
7565
animation: 1s spin linear infinite;

src/components/PageHeader.vue

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1+
<script lang="ts" setup>
2+
interface Props {
3+
inline?: boolean
4+
}
5+
6+
withDefaults(defineProps<Props>(), {
7+
inline: false,
8+
})
9+
</script>
10+
111
<template>
2-
<header class="header">
12+
<header
13+
class="header"
14+
:class="{ 'header-inline': inline }"
15+
>
316
<slot />
417
</header>
518
</template>
@@ -8,5 +21,9 @@
821
.header {
922
font-size: 16px;
1023
color: var(--white);
24+
25+
&-inline {
26+
display: inline-block;
27+
}
1128
}
1229
</style>

src/composables/useKey.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { tryOnScopeDispose } from '@vueuse/core'
12
import hotkeys, { type HotkeysEvent } from 'hotkeys-js'
2-
import { type Ref, onMounted, onUnmounted, unref, watch } from 'vue'
3+
import { type Ref, isRef, unref, watch } from 'vue'
34

45
type MaybeRef<T> = T | Ref<T>
56

@@ -97,7 +98,7 @@ export function useKey(
9798
}
9899
}
99100

100-
if (source) {
101+
if (isRef(source) || typeof source === 'function') {
101102
watch(
102103
source,
103104
(newSourceValue) => {
@@ -109,8 +110,10 @@ export function useKey(
109110
)
110111
}
111112
else {
112-
onMounted(init)
113+
init()
113114
}
114115

115-
onUnmounted(destroy)
116+
tryOnScopeDispose(destroy)
117+
118+
return destroy
116119
}

src/pages/SettingsPage.vue

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
<script lang="ts" setup>
22
import { watch } from 'vue'
33
import { exit } from '@tauri-apps/api/process'
4-
import { open } from '@tauri-apps/api/shell'
54
import { invoke } from '@tauri-apps/api/tauri'
5+
import { disable as disableAutostart, enable as enableAutostart } from 'tauri-plugin-autostart-api'
6+
import { watchDebounced } from '@vueuse/core'
67
import AppButton from '../components/AppButton.vue'
78
import PageHeader from '../components/PageHeader.vue'
89
import SettingsItem from '../components/SettingsItem.vue'
910
import { useStore } from '../stores/store'
1011
import { AppStorage } from '../storage'
12+
import { InvokeCommand, Page } from '../constants'
1113
import { Icons } from '../components/Icons'
12-
import { REPO_LINK } from '../constants'
14+
import { useKey } from '../composables/useKey'
1315
1416
const store = useStore()
1517
@@ -22,15 +24,44 @@ const accessToken = AppStorage.asComputed('accessToken')
2224
2325
watch(soundsEnabled, (enabled) => {
2426
if (enabled)
25-
invoke('play_notification_sound')
27+
invoke(InvokeCommand.PlayNotificationSound)
2628
})
29+
30+
watchDebounced(openAtStartup, (enabled) => {
31+
if (enabled)
32+
enableAutostart()
33+
else
34+
disableAutostart()
35+
}, { debounce: 350 })
36+
37+
function handleBack() {
38+
let page = Page.Home
39+
40+
if (accessToken.value == null)
41+
page = Page.Landing
42+
43+
store.setPage(page)
44+
}
45+
46+
useKey('esc', handleBack, { prevent: true })
2747
</script>
2848

2949
<template>
3050
<div class="settings">
31-
<PageHeader class="settings-header">
32-
Settings
33-
</PageHeader>
51+
<div class="settings-header">
52+
<AppButton
53+
class="settings-header-back-button"
54+
square
55+
title="Go back"
56+
@click="handleBack"
57+
>
58+
<Icons.ChevronLeft />
59+
</AppButton>
60+
61+
<PageHeader inline>
62+
Settings
63+
</PageHeader>
64+
</div>
3465

3566
<div class="settings-grid">
3667
<SettingsItem
@@ -52,14 +83,6 @@ watch(soundsEnabled, (enabled) => {
5283
</div>
5384

5485
<div class="settings-footer">
55-
<AppButton
56-
title="Open Gitification repository"
57-
class="github-button"
58-
@click="open(REPO_LINK)"
59-
>
60-
<Icons.Github />
61-
</AppButton>
62-
6386
<AppButton
6487
v-if="accessToken"
6588
@click="store.logout"
@@ -89,6 +112,10 @@ watch(soundsEnabled, (enabled) => {
89112
90113
&-header {
91114
margin-bottom: 25px;
115+
116+
&-back-button {
117+
margin-right: 10px;
118+
}
92119
}
93120
94121
&-grid {
@@ -110,8 +137,4 @@ watch(soundsEnabled, (enabled) => {
110137
}
111138
}
112139
}
113-
114-
.github-button {
115-
margin-right: auto;
116-
}
117140
</style>

0 commit comments

Comments
 (0)