generated from kuba1pie/vueTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTheEditor.vue
135 lines (127 loc) · 3.5 KB
/
TheEditor.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
<script setup lang="ts">
import type { Message } from '../types'
const store = useDefaultStore()
store.getCharacters()
const newMessage: Message = reactive({ title: import.meta.env.VITE_MESSAGE_TITLE, message: import.meta.env.VITE_MESSAGE_CONTENT, recipient: '', timestamp: new Date(Date.now()), checkbox: false })
let archiveData: Message[] = []
const isDisabled = computed(() => {
if (newMessage.title === '' || newMessage.message === '' || newMessage.recipient === '')
return true
else
return false
})
async function onSubmitClick() {
if (window.localStorage.getItem('archiveData')) {
archiveData = JSON.parse(window.localStorage.getItem('archiveData')!)
newMessage.timestamp = new Date(Date.now())
archiveData.push(newMessage)
window.localStorage.setItem('archiveData', (JSON.stringify(archiveData)))
}
else {
newMessage.timestamp = new Date(Date.now())
archiveData.push(newMessage)
window.localStorage.setItem('archiveData', (JSON.stringify(archiveData)))
}
newMessage.title = ''
newMessage.message = ''
newMessage.recipient = ''
newMessage.checkbox = false
}
</script>
<template>
<div class="c-theEditor flex flex-col w-200">
<h2>Send a new message</h2>
<form
action="#"
class="flex flex-col"
>
<div class="form__title">
<label for="input">Title</label>
<input
v-model="newMessage.title"
placeholder="Enter the title"
name="input"
:class="{ error: !newMessage.title }"
>
</div>
<div class="form__message flex-col">
<label for="text">Message</label>
<textarea
v-model="newMessage.message"
name="text"
placeholder="Enter the message here..."
:class="{ error: !newMessage.message }"
maxlength="256"
class="h-50"
/>
</div>
<div class="form__character">
<label for="select">Character</label>
<select
v-model="newMessage.recipient"
name="select"
:class="{ error: !newMessage.recipient }"
>
<option
value=""
disabled
selected
hidden
>
Pick a character
</option>
<option
v-for="item in store.charactersData.results"
:key="item.id"
:value="item.id"
>
{{ item.name }}
</option>
</select>
</div>
<div class="form__checkbox flex flex-row justify-between">
<label for="checkbox">Important</label>
<input
id="checkbox"
v-model="newMessage.checkbox"
type="checkbox"
name="checkbox"
class="checkbox w-8"
>
</div>
<div class="form__button">
<button
type="submit"
:class="{ 'bg-red-500/20': isDisabled }"
:disabled="isDisabled"
class="c-tabButton bg-green-500/20 px-8 py-3 text-8 w-80 m-0 border-0"
@click="onSubmitClick()"
>
Send
</button>
<button
type="submit"
class="c-tabButton bg-grey-500/20 px-8 py-3 text-8 w-80 m-0 my-10 border-0"
@click="store.activeTab = 'TheArchive'"
>
Go to Archive
</button>
</div>
</form>
</div>
</template>
<style lang="scss" scope>
form > div {
display: flex;
flex-flow: column;
margin: 0.4em 0;
label {
margin-bottom: 0.3em;
}
input,
textarea,
select {
font-size: 0.6em;
}
}
</style>