-
Notifications
You must be signed in to change notification settings - Fork 143
/
row.svelte
157 lines (146 loc) · 5.97 KB
/
row.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
<script lang="ts">
import { tooltip } from '$lib/actions/tooltip';
import { sdk } from '$lib/stores/sdk';
import type { Models } from '@appwrite.io/console';
import { tick } from 'svelte';
import { AvatarInitials } from '../';
import Output from '../output.svelte';
export let role: string;
let content: HTMLDivElement;
let data = null;
let isFetching = false;
async function getData(
permission: string
): Promise<
Partial<Models.User<Record<string, unknown>> & Models.Team<Record<string, unknown>>>
> {
const role = permission.split(':')[0];
const id = permission.split(':')[1].split('/')[0];
if (role === 'user') {
const user = await sdk.forProject.users.get(id);
return user;
}
if (role === 'team') {
const team = await sdk.forProject.teams.get(id);
return team;
}
}
</script>
<div class="u-flex u-cross-center u-gap-8 tippy-user">
<div>
{#if role === 'users'}
<div>Users</div>
{:else if role === 'guests'}
<div>Guests</div>
{:else if role === 'any'}
<div>Any</div>
{:else}
<div
class="u-trim-1"
use:tooltip={{
interactive: true,
allowHTML: true,
onShow(instance) {
if (isFetching || data) {
return;
}
getData(role)
.then((n) => {
data = n;
})
.finally(() => {
tick().then(() => {
instance.setContent(content);
});
});
}
}}>
{role}
</div>
<div class="u-hide">
<div bind:this={content}>
{#if data}
{@const isUser = role.startsWith('user')}
{@const isTeam = role.startsWith('team')}
{@const isAnonymous = !data.email && !data.phone && isUser}
<div class="user-profile">
{#if isAnonymous}
<div class="avatar is-size-small">
<span class="icon-anonymous" aria-hidden="true" />
</div>
{:else if data.name}
<AvatarInitials name={data.name} size={40} />
{:else}
<div class="avatar is-size-small">
<span class="icon-minus-sm" aria-hidden="true" />
</div>
{/if}
<span class="user-profile-info is-only-desktop">
<span class="name">
{data.name ?? data?.email ?? data?.phone ?? '-'}
</span>
<Output value={data.$id}>{role}</Output>
</span>
{#if (isUser && (data?.email || data?.phone)) || isTeam}
<span class="user-profile-sep" />
<span class="user-profile-empty-column" />
<span class="user-profile-info is-only-desktop">
{#if isUser}
<div class="u-grid u-gap-4">
{#if data?.email}
<p class="text u-x-small">Email: {data?.email}</p>
{/if}
{#if data?.phone}
<p class="text u-x-small">Phone: {data?.phone}</p>
{/if}
</div>
{:else if isTeam}
<p class="text u-x-small">Members: {data?.total}</p>
{/if}
</span>
{/if}
</div>
{:else}
Not found.
{/if}
</div>
</div>
{/if}
</div>
</div>
<style lang="scss" global>
.tippy-user .tippy-box {
--p-drop-bg-color: var(--color-neutral-500);
--p-drop-border-color: var(--color-neutral-200);
body.theme-light & {
--p-drop-bg-color: var(--color-neutral-0);
--p-drop-border-color: var(--color-neutral-10);
}
inset-inline-start: -0.625rem;
inset-block-end: calc(100% + 0.625rem);
background-color: hsl(var(--p-drop-bg-color));
border: solid 0.0625rem hsl(var(--p-drop-border-color));
border-radius: var(--border-radius-small);
box-shadow: var(--shadow-small);
font-size: var(--font-size-0);
color: hsl(var(--p-body-text-color));
max-inline-size: 32.5rem;
margin-inline: auto;
line-height: 1.5;
.tippy-content {
padding: 1rem;
}
&[data-placement^='top'] > .tippy-arrow::before {
border-top-color: hsl(var(--p-drop-bg-color));
}
&[data-placement^='bottom'] > .tippy-arrow::before {
border-bottom-color: hsl(var(--p-drop-bg-color));
}
&[data-placement^='left'] > .tippy-arrow::before {
border-left-color: hsl(var(--p-drop-bg-color));
}
&[data-placement^='right'] > .tippy-arrow::before {
border-right-color: hsl(var(--p-drop-bg-color));
}
}
</style>