-
Notifications
You must be signed in to change notification settings - Fork 6
/
MainView.svelte
264 lines (232 loc) · 7.15 KB
/
MainView.svelte
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<script lang="ts">
import TopAppBar, {Row, Section, Title} from '@smui/top-app-bar';
import IconButton from '@smui/icon-button';
import Drawer, {Content, Header, Title as DrawerTitle, Subtitle, Scrim} from '@smui/drawer';
import List, {Item, Text, Graphic, Separator, Meta} from '@smui/list';
import Chip, {Text as ChipText} from '@smui/chips';
import Button, {Group, Label} from '@smui/button';
import Perspective from './Perspective.svelte';
import LanguagesSettings from './LanguagesSettings.svelte'
import PerspectiveSettings from './PerspectiveSettings.svelte'
import { getClient, mutation, query } from "svelte-apollo";
import { ADD_PERSPECTIVE, PERSPECTIVES, PERSPECTIVE_ADDED, PERSPECTIVE_REMOVED, PERSPECTIVE_UPDATED, REMOVE_PERSPECTIVE } from './graphql_queries';
import AgentProfileSettings from './AgentProfileSettings.svelte';
let perspectives = query(PERSPECTIVES)
const M_ADD_PERSPECTIVE = mutation(ADD_PERSPECTIVE)
const M_REMOVE_PERSPECTIVE = mutation(REMOVE_PERSPECTIVE)
let collapsed = false;
let collapsing = false;
let drawerOpen = false;
let drawer
let hovered
$: if(!$perspectives.loading && $perspectives.data) {
hovered = {}
$perspectives.data.perspectives.forEach(p => {
hovered[p.uuid] = true
})
}
//for(const pID in $perspectiveStore) {
// linkRepoController.syncWithSharingAdapter($perspectiveStore[pID])
//}
getClient().subscribe({
query: PERSPECTIVE_ADDED
}).subscribe({
next: () => perspectives.fetchMore({}),
error: (e) => console.error(e)
})
getClient().subscribe({
query: PERSPECTIVE_UPDATED
}).subscribe({
next: () => perspectives.refetch({}),
error: (e) => console.error(e)
})
getClient().subscribe({
query: PERSPECTIVE_REMOVED
}).subscribe({
next: () => perspectives.refetch({}),
error: (e) => console.error(e)
})
let selectedMainView = {
perspective: null,
settings: null,
edit: null,
}
function createNewPerspective() {
let number = 1
let prefix = "New Perspective "
while($perspectives.data.perspectives.includes(prefix+number)) {
number++
}
const name = prefix+number
M_ADD_PERSPECTIVE({
variables: {
name
}
})
}
function deletePerspective(perspective) {
if(selectedMainView.perspective == perspective) {
selectedMainView.perspective = null
}
M_REMOVE_PERSPECTIVE({
variables: {
uuid: perspective.uuid
}
})
}
function editPerspective(perspective) {
selectedMainView.perspective = null
selectedMainView.settings = null
selectedMainView.edit = perspective
}
function editPerspectiveSubmit(event) {
const uuid = event.detail
console.log(uuid)
//const perspective = $perspectiveStore[uuid]
//perspectiveStore.update(perspective)
//linkRepoController.syncWithSharingAdapter(perspective)
if(selectedMainView.perspective == null) {
selectedMainView.perspective = selectedMainView.edit
selectedMainView.settings = null
selectedMainView.edit = null
}
}
</script>
<Drawer variant="modal" bind:this={drawer} bind:open={drawerOpen}>
<Header>
<DrawerTitle>Perspectives</DrawerTitle>
<Subtitle>Switch to perspective from list</Subtitle>
</Header>
<Content>
<List>
{#if $perspectives.data?.perspectives?.length == 0}
<Chip><ChipText>No Perspectives yet</ChipText></Chip>
{/if}
{#if $perspectives.loading}
<Chip><ChipText>Loading...</ChipText></Chip>
{:else}
{#each $perspectives.data.perspectives as perspective}
<Item href="javascript:void(0)"
on:mouseenter="{e => hovered[perspective.uuid] = false}"
on:mouseleave="{e => hovered[perspective.uuid] = true}"
activated={selectedMainView.perspective?.uuid == perspective.uuid}
on:click={() => selectedMainView = { perspective, settings: null }}
>
<Text>{perspective.name}</Text>
{#if !hovered[perspective.uuid]}
<Meta>
<div on:click|stopPropagation="">
<Group variant="unelevated">
<Button variant="unelevated" color="secondary" on:click={()=>deletePerspective(perspective)}>
<Label>Delete</Label>
</Button>
<Button variant="unelevated" on:click={(event)=>{
editPerspective(perspective)
}}>
<Label>Edit</Label>
</Button>
</Group>
</div>
</Meta>
{/if}
</Item>
{/each}
{/if}
<Item on:click={()=>createNewPerspective()}>
<Graphic class="material-icons" aria-hidden="true">note_add</Graphic>
<Text>Create Perspective</Text>
</Item>
<Separator nav />
<Header>
<DrawerTitle>Settings</DrawerTitle>
<Subtitle>
Manage installed Languages and other stuff
</Subtitle>
</Header>
<Item
activated={selectedMainView.settings == 'languages'}
on:click={() => selectedMainView = { perspective: null, settings: 'languages' }}
>
<Graphic class="material-icons" aria-hidden="true">insert_comment</Graphic>
<Text>Manage Languages</Text>
</Item>
<Item
activated={selectedMainView.settings == 'agent'}
on:click={() => selectedMainView = { perspective: null, settings: 'agent' }}
>
<Graphic class="material-icons" aria-hidden="true">account_circle</Graphic>
<Text>Agent Profile</Text>
</Item>
</List>
</Content>
</Drawer>
<Scrim></Scrim>
<TopAppBar dense='true' variant='static'
bind:collapsed
on:mouseenter="{e => collapsing ? collapsed=false : undefined}"
on:mouseleave="{e => collapsing ? collapsed=true : undefined}"
>
<Row>
<Section>
<IconButton class="material-icons" on:click={() => {drawerOpen = !drawerOpen}}>menu</IconButton>
<Title>
Perspectivism
{#if selectedMainView.perspective}
> {selectedMainView.perspective.name}
{:else if selectedMainView.settings }
> {selectedMainView.settings}
{:else if selectedMainView.edit }
> Editing Perspective "{selectedMainView.edit.name }"
{/if}
</Title>
</Section>
</Row>
</TopAppBar>
{#if selectedMainView.perspective}
<Perspective perspective={selectedMainView.perspective}
on:settings-changed={editPerspectiveSubmit}
></Perspective>
{:else if selectedMainView.settings }
{#if selectedMainView.settings == 'languages'}
<LanguagesSettings></LanguagesSettings>
{/if}
{#if selectedMainView.settings == 'agent'}
<div class="centered">
<AgentProfileSettings></AgentProfileSettings>
</div>
{/if}
{:else if selectedMainView.edit }
<PerspectiveSettings perspective={JSON.parse(JSON.stringify(selectedMainView.edit))}
on:submit={editPerspectiveSubmit}
on:cancel={() => selectedMainView.edit = null}
></PerspectiveSettings>
{:else}
<h1>Welcome to Perspectivism!</h1>
<h2>Please open the drawer and create or select a perspective to start...</h2>
{/if}
<style>
main {
height: 100%;
text-align: center;
padding: 0;
max-width: 240px;
margin: 0 auto;
}
h1 {
color: #00c3ff;
text-transform: uppercase;
font-size: 4em;
font-weight: 100;
}
.centered {
margin-top: 100px;
margin-left: auto;
margin-right: auto;
width: 380px;
}
@media (min-width: 640px) {
main {
max-width: none;
}
}
</style>