-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f42174f
commit 8dbaa79
Showing
11 changed files
with
190 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
import { | ||
useAccountIsConnected, | ||
useAllAccounts, | ||
} from '@mintter/app/src/models/accounts' | ||
import {useNavigate} from '@mintter/app/src/utils/navigation' | ||
import {Avatar} from '@mintter/app/src/components/avatar' | ||
import Footer from '@mintter/app/src/components/footer' | ||
import {OnlineIndicator} from '@mintter/app/src/components/indicator' | ||
import {Account} from '@mintter/shared' | ||
import { | ||
Button, | ||
Container, | ||
Heading, | ||
MainWrapper, | ||
Spinner, | ||
Text, | ||
XStack, | ||
YStack, | ||
styled, | ||
} from '@mintter/ui' | ||
import {useSetTrusted} from '../models/accounts' | ||
import {PlusCircle} from '@tamagui/lucide-icons' | ||
|
||
const PageHeading = styled(Heading, { | ||
color: '$gray10', | ||
fontSize: '$7', | ||
fontWeight: 'normal', | ||
}) | ||
|
||
function ContactItem({ | ||
account, | ||
isTrusted, | ||
}: { | ||
account: Account | ||
isTrusted: boolean | ||
}) { | ||
const navigate = useNavigate() | ||
const isConnected = useAccountIsConnected(account) | ||
const alias = account.profile?.alias | ||
const setTrusted = useSetTrusted() | ||
return ( | ||
<Button | ||
chromeless | ||
theme="gray" | ||
tag="li" | ||
gap="$4" | ||
onPress={() => { | ||
navigate({key: 'account', accountId: account.id}) | ||
}} | ||
> | ||
<XStack alignItems="center" gap="$4" flex={1}> | ||
<Avatar | ||
size="$2" | ||
accountId={account.id} | ||
alias={account.profile?.alias || ''} | ||
/> | ||
{alias ? ( | ||
<Text fontWeight="700" fontFamily="$body"> | ||
{alias} | ||
</Text> | ||
) : ( | ||
<Text fontFamily="$body" fontWeight="bold" color="muted"> | ||
{account.id.slice(0, 5)}...{account.id.slice(-5)} | ||
</Text> | ||
)} | ||
</XStack> | ||
{!isTrusted && ( | ||
<Button | ||
onPress={(e) => { | ||
e.stopPropagation() | ||
setTrusted.mutate({accountId: account.id, isTrusted: true}) | ||
}} | ||
icon={PlusCircle} | ||
> | ||
Trust | ||
</Button> | ||
)} | ||
<OnlineIndicator online={isConnected} /> | ||
</Button> | ||
) | ||
} | ||
|
||
function ErrorPage({}: {error: any}) { | ||
// todo, this! | ||
return ( | ||
<MainWrapper> | ||
<Container> | ||
<Text fontFamily="$body" fontSize="$3"> | ||
Error | ||
</Text> | ||
</Container> | ||
</MainWrapper> | ||
) | ||
} | ||
|
||
export default function ContactsPage() { | ||
const contacts = useAllAccounts() | ||
const allAccounts = contacts.data?.accounts || [] | ||
const trustedAccounts = allAccounts.filter((account) => account.isTrusted) | ||
const untrustedAccounts = allAccounts.filter((account) => !account.isTrusted) | ||
if (contacts.isLoading) { | ||
return ( | ||
<MainWrapper> | ||
<Container> | ||
<Spinner /> | ||
</Container> | ||
</MainWrapper> | ||
) | ||
} | ||
if (contacts.error) { | ||
return <ErrorPage error={contacts.error} /> | ||
} | ||
if (allAccounts.length === 0) { | ||
return ( | ||
<MainWrapper> | ||
<Container> | ||
<YStack gap="$5" paddingVertical="$8"> | ||
<Text fontFamily="$body" fontSize="$3"> | ||
You have no Contacts yet. | ||
</Text> | ||
</YStack> | ||
</Container> | ||
</MainWrapper> | ||
) | ||
} | ||
return ( | ||
<> | ||
<MainWrapper> | ||
<Container marginVertical="$4"> | ||
{trustedAccounts.length ? ( | ||
<> | ||
<PageHeading>Trusted Contacts</PageHeading> | ||
<YStack tag="ul" padding={0} gap="$2"> | ||
{trustedAccounts.map((account) => { | ||
return ( | ||
<ContactItem | ||
key={account.id} | ||
account={account} | ||
isTrusted={true} | ||
/> | ||
) | ||
})} | ||
</YStack> | ||
<PageHeading marginTop="$4">Other Contacts</PageHeading> | ||
</> | ||
) : null} | ||
<YStack tag="ul" padding={0} gap="$2"> | ||
{untrustedAccounts.map((account) => { | ||
return ( | ||
<ContactItem | ||
key={account.id} | ||
account={account} | ||
isTrusted={false} | ||
/> | ||
) | ||
})} | ||
</YStack> | ||
</Container> | ||
</MainWrapper> | ||
<Footer /> | ||
</> | ||
) | ||
} |
Oops, something went wrong.