|
| 1 | +import { For, Show } from 'solid-js'; |
| 2 | +import { LogOut01Icon, PlusIcon, Settings01Icon } from '@untitled-theme/icons-solid'; |
| 3 | +import { useNavigate } from '@solidjs/router'; |
| 4 | +import Button from '../../base/Button'; |
| 5 | +import PlayerHead from '../../game/PlayerHead'; |
| 6 | +import Popup from '../Popup'; |
| 7 | +import useAccountController from './AddAccountModal'; |
| 8 | +import type { MinecraftCredentials } from '~bindings'; |
| 9 | + |
| 10 | +interface AccountComponentProps { |
| 11 | + account: MinecraftCredentials | null | undefined; |
| 12 | + loggedIn?: boolean; |
| 13 | +} |
| 14 | + |
| 15 | +function AccountComponent(props: AccountComponentProps) { |
| 16 | + return ( |
| 17 | + <Show when={props.account}> |
| 18 | + <div class={`flex flex-row justify-between p-2 rounded-lg ${!props.loggedIn && 'hover:bg-gray-05 active:bg-gray-10 hover:text-fg-primary-hover'}`}> |
| 19 | + <div class="flex flex-row justify-start flex-1 gap-x-3"> |
| 20 | + <PlayerHead class="w-8 h-8 rounded-md" uuid={props.account!.id} /> |
| 21 | + <div class="flex flex-col items-center justify-center"> |
| 22 | + <div class="flex flex-col items-start justify-between"> |
| 23 | + <p class="font-semibold h-[18px]">{props.account!.username}</p> |
| 24 | + {props.loggedIn && <p class="text-xs">Logged in</p>} |
| 25 | + </div> |
| 26 | + </div> |
| 27 | + </div> |
| 28 | + {props.loggedIn && ( |
| 29 | + <Button buttonStyle="icon"> |
| 30 | + <LogOut01Icon class=" stroke-danger" /> |
| 31 | + </Button> |
| 32 | + )} |
| 33 | + </div> |
| 34 | + </Show> |
| 35 | + ); |
| 36 | +} |
| 37 | + |
| 38 | +function AccountPopup(props: Popup.PopupProps) { |
| 39 | + const controller = useAccountController(); |
| 40 | + |
| 41 | + const filteredAccounts = () => controller.accounts()?.filter(account => account.id !== controller.defaultAccount()?.id) ?? []; |
| 42 | + |
| 43 | + const navigate = useNavigate(); |
| 44 | + |
| 45 | + return ( |
| 46 | + <Popup {...props}> |
| 47 | + <div class="bg-secondary rounded-xl border border-gray-10 w-72 p-2 shadow-md shadow-black/30"> |
| 48 | + <div class="flex flex-col gap-y-2 text-fg-primary"> |
| 49 | + <AccountComponent account={controller.defaultAccount()} loggedIn /> |
| 50 | + |
| 51 | + <Show when={filteredAccounts().length !== 0}> |
| 52 | + <div class="w-full h-px bg-gray-05 rounded-md" /> |
| 53 | + <For each={filteredAccounts()}> |
| 54 | + {account => ( |
| 55 | + <AccountComponent account={account} /> |
| 56 | + )} |
| 57 | + </For> |
| 58 | + <div class="w-full h-px bg-gray-05 rounded-md" /> |
| 59 | + </Show> |
| 60 | + |
| 61 | + <div class="flex flex-row justify-between"> |
| 62 | + <div> |
| 63 | + <Button |
| 64 | + buttonStyle="ghost" |
| 65 | + iconLeft={<PlusIcon />} |
| 66 | + onClick={() => { |
| 67 | + props.setVisible(false); |
| 68 | + controller.displayAddAccount(); |
| 69 | + }} |
| 70 | + > |
| 71 | + Add Account |
| 72 | + </Button> |
| 73 | + </div> |
| 74 | + <div class="flex flex-row"> |
| 75 | + <Button |
| 76 | + buttonStyle="icon" |
| 77 | + large |
| 78 | + onClick={() => { |
| 79 | + props.setVisible(false); |
| 80 | + navigate('/settings/accounts'); |
| 81 | + }} |
| 82 | + > |
| 83 | + <Settings01Icon class="stroke-fg-primary" /> |
| 84 | + </Button> |
| 85 | + </div> |
| 86 | + </div> |
| 87 | + |
| 88 | + </div> |
| 89 | + </div> |
| 90 | + </Popup> |
| 91 | + ); |
| 92 | +} |
| 93 | + |
| 94 | +export default AccountPopup; |
0 commit comments