-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.vue
159 lines (144 loc) · 4.3 KB
/
App.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<script lang="ts">
import InputForm from './components/InputForm.vue'
import ActivityTable from './components/ActivityTable.vue'
import ConvertionWindow from './components/ConvertionWindow.vue'
import InfoMenu from './components/InfoMenu.vue'
import SettingsMenu from './components/SettingsMenu.vue'
import type { Activity } from './types.ts'
import { defineComponent } from 'vue'
import { useStore } from '@/store'
export default defineComponent({
data() {
return {
activities: [] as Activity[],
id: 0,
duringConversion: false,
showInfo: false,
showSettings: false
}
},
beforeMount() {
useStore().commit('init')
},
mounted() {
let a = localStorage.getItem('activities')
if (a != null) {
this.activities = JSON.parse(a)
}
},
methods: {
addActivity(title: string, time: number, description: string) {
let a: Activity = { Id: this.id, Title: title, Duration: time, Description: description }
this.id++
this.activities.push(a)
this.updateLocalStorage()
},
removeActivity(id: Number): void {
this.activities = this.activities.filter((x) => x.Id !== id)
this.updateLocalStorage()
},
clearAll(): void {
this.activities = []
this.updateLocalStorage()
},
updateLocalStorage(): void {
localStorage.setItem('activities', JSON.stringify(this.activities))
},
convert(): void {
this.switchMode()
window.scrollTo(0, 0)
},
canConvert(): boolean {
return this.activities.length > 0
},
switchMode(): void {
if (this.activities.length <= 0) {
this.duringConversion = false
} else {
this.duringConversion = !this.duringConversion
}
}
},
components: { InputForm, ActivityTable, ConvertionWindow, InfoMenu, SettingsMenu }
})
</script>
<template>
<div>
<div class="flex justify-center">
<div class="mt-10 w-[60em]">
<div class="flex justify-between sm:absolute sm:top-0 sm:right-0 w-full px-10 mt-10 mb-2">
<button @click="showInfo = !showInfo">
<span class="icon-[solar--hamburger-menu-linear] text-3xl"></span>
</button>
<button @click="showSettings = !showSettings">
<span class="icon-[solar--settings-outline] text-3xl"></span>
</button>
</div>
<h1 class="p-2 text-center text-3xl font-bold">Diario tirocinio</h1>
<h3 class="text-center mb-10">Riassumi velocemente il tuo tirocinio</h3>
<div class="flex justify-between border-b-cartabinaria-dark-blu border-b-4">
<button
@click="switchMode"
:disabled="!duringConversion"
class="w-full p-4 rounded-tl-lg enabled:hover:bg-blue-400 font-bold"
:class="{
'bg-cartabinaria-light-blu': duringConversion,
'bg-blue-500': !duringConversion
}"
>
Insert
</button>
<button
@click="switchMode"
:disabled="duringConversion || !canConvert()"
class="w-full p-4 rounded-tr-lg font-bold"
:class="{
'bg-cartabinaria-light-blu': !duringConversion,
'bg-blue-500': duringConversion,
'enabled:hover:bg-blue-400': canConvert(),
'opacity-50': !canConvert()
}"
>
Convert
</button>
</div>
<div v-show="!duringConversion">
<InputForm @addActivity="addActivity" />
<ActivityTable
v-show="activities.length > 0"
:activities="activities"
@removeActivity="removeActivity"
@clearAll="clearAll"
@convert="convert"
/>
</div>
<div v-show="duringConversion">
<ConvertionWindow :activities="activities" />
</div>
</div>
</div>
<div>
<InfoMenu
@close="showInfo = false"
class="menu"
:class="{ 'left-[-20rem]': !showInfo, 'left-0': showInfo }"
/>
<SettingsMenu
@close="showSettings = false"
class="menu"
:class="{ 'right-[-20rem]': !showSettings, 'right-0': showSettings }"
/>
</div>
</div>
</template>
<style>
* {
color: white;
}
.menu {
position: fixed;
height: 100%;
top: 0;
transition: all 1s;
}
</style>