Files
radicle-explorer/src/base/users/View.svelte
T
2021-11-26 09:38:54 +01:00

214 lines
5.9 KiB
Svelte

<script lang="ts">
import type { SvelteComponent } from 'svelte';
import type { Config } from '@app/config';
import Icon from '@app/Icon.svelte';
import Address from '@app/Address.svelte';
import Avatar from '@app/Avatar.svelte';
import { ProfileType, Profile } from '@app/profile';
import Loading from '@app/Loading.svelte';
import { Org } from '@app/base/orgs/Org';
import Message from '@app/Message.svelte';
import Project from '@app/base/projects/Widget.svelte';
import { session } from '@app/session';
import { isAddressEqual } from '@app/utils';
import Error from '@app/Error.svelte';
import SetName from '@app/ens/SetName.svelte';
import { User } from '@app/base/users/User';
export let addressOrName: string;
export let config: Config;
export let action: string | null = null;
let setNameForm: typeof SvelteComponent | null =
action === "setName" ? SetName : null;
const setName = () => {
setNameForm = SetName;
};
$: isAuthorized = (address: string): boolean | null => {
return $session && isAddressEqual(address, $session.address);
};
</script>
<style>
main {
padding: 5rem 0;
width: 36rem;
}
main > header {
display: flex;
align-items: center;
justify-content: left;
margin-bottom: 2rem;
}
main > header > * {
margin: 0 1rem 0 0;
}
.info {
display: flex;
flex-direction: column;
justify-content: center;
align-items: left;
}
.info a {
border: none;
}
.fields {
display: grid;
grid-template-columns: 5rem 4fr 2fr;
grid-gap: 1rem 2rem;
}
.fields > div {
justify-self: start;
align-self: center;
height: 2rem;
line-height: 2rem;
}
.avatar {
width: 64px;
height: 64px;
}
.links {
display: flex;
align-items: center;
justify-content: left;
}
.url {
display: flex; /* Ensures correct vertical positioning of icons */
margin-right: 1rem;
}
.projects {
margin-top: 2rem;
}
.projects .project {
margin-bottom: 1rem;
}
.members {
margin-top: 2rem;
align-items: center;
display: flex;
}
.members .member {
display: flex;
align-items: center;
margin-right: 2rem;
}
.members .member:last-child {
margin-right: 0;
}
.members .member-icon {
width: 2rem;
height: 2rem;
margin-right: 1rem;
}
</style>
<svelte:head>
<title>{addressOrName}</title>
</svelte:head>
{#await Profile.get(addressOrName, ProfileType.Full, config)}
<Loading fadeIn />
{:then profile}
<main>
<header>
<div class="avatar">
<Avatar source={profile.avatar ?? profile.address} address={profile.address} />
</div>
<div class="info">
<span class="title bold">
<Address compact noAvatar noBadge {profile} address={profile.address} {config} resolve/>
</span>
<div class="links">
{#if profile.url}
<a class="url" href={profile.url}>{profile.url}</a>
{/if}
{#if profile.twitter}
<a class="url" href="https://twitter.com/{profile.twitter}">
<Icon name="twitter" inline />
</a>
{/if}
{#if profile.github}
<a class="url" href="https://github.com/{profile.github}">
<Icon name="github" inline />
</a>
{/if}
</div>
</div>
</header>
<div class="fields">
<!-- Address -->
<div class="label">Address</div>
<div><Address {config} address={profile.address} /></div>
<div></div>
<!-- Project anchors -->
{#if profile.anchorsAccount}
<div class="label">Anchors</div>
<div><Address {config} address={profile.anchorsAccount} /></div>
<div></div>
{/if}
<!-- Profile -->
<div class="label">Profile</div>
<div>
{#if profile.name}
<a href={profile.registry(config)} class="link">{profile.name}</a>
{:else}
<span class="subtle">Not set</span>
{/if}
</div>
<div>
{#if (isAuthorized(profile.address))}
<button class="tiny secondary" on:click={setName}>
Set
</button>
{/if}
</div>
</div>
{#await Org.getOrgsByMember(profile.address, config)}
<Loading center />
{:then orgs}
{#if orgs.length > 0}
<div class="members">
{#each orgs as org}
{#await Profile.get(org.address, ProfileType.Minimal, config)}
<Loading small margins />
{:then profile}
<div class="member">
<div class="member-icon">
<Avatar source={profile.avatar ?? profile.address} address={profile.address} />
</div>
<Address address={profile.address} compact
resolve noBadge noAvatar {profile} {config} />
</div>
{/await}
{/each}
</div>
{/if}
{/await}
<div class="projects">
{#if profile.anchorsAccount}
{#await Org.get(profile.anchorsAccount, config)}
<Loading center fadeIn />
{:then org}
{#if org}
{#await org.getProjects(config) then projects}
{#each projects as project}
<div class="project">
<Project {project} user={addressOrName} config={profile.config(config)} />
</div>
{/each}
{:catch err}
<Message error>
<strong>Error: </strong> failed to load projects: {err.message}.
</Message>
{/await}
{/if}
{/await}
{/if}
</div>
</main>
<svelte:component this={setNameForm} entity={new User(profile.address)} {config} on:close={() => setNameForm = null} />
{:catch err}
<Error error={err} />
{/await}