mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-14 11:10:29 +03:00
add share user button in user profile
This commit is contained in:
parent
ad3916b70d
commit
13b0dd174d
2 changed files with 86 additions and 1 deletions
|
|
@ -36,6 +36,8 @@ import { useAllJoinedRoomsSet, useGetRoom } from '../../hooks/useGetRoom';
|
||||||
import { RoomAvatar, RoomIcon } from '../room-avatar';
|
import { RoomAvatar, RoomIcon } from '../room-avatar';
|
||||||
import { getDirectRoomAvatarUrl, getRoomAvatarUrl } from '../../utils/room';
|
import { getDirectRoomAvatarUrl, getRoomAvatarUrl } from '../../utils/room';
|
||||||
import { nameInitials } from '../../utils/common';
|
import { nameInitials } from '../../utils/common';
|
||||||
|
import { getMatrixToUser } from '../../plugins/matrix-to';
|
||||||
|
import { useTimeoutToggle } from '../../hooks/useTimeoutToggle';
|
||||||
|
|
||||||
export function ServerChip({ server }: { server: string }) {
|
export function ServerChip({ server }: { server: string }) {
|
||||||
const mx = useMatrixClient();
|
const mx = useMatrixClient();
|
||||||
|
|
@ -135,6 +137,88 @@ export function ServerChip({ server }: { server: string }) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function ShareChip({ userId }: { userId: string }) {
|
||||||
|
const [cords, setCords] = useState<RectCords>();
|
||||||
|
|
||||||
|
const [copied, setCopied] = useTimeoutToggle();
|
||||||
|
|
||||||
|
const open: MouseEventHandler<HTMLButtonElement> = (evt) => {
|
||||||
|
setCords(evt.currentTarget.getBoundingClientRect());
|
||||||
|
};
|
||||||
|
|
||||||
|
const close = () => setCords(undefined);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PopOut
|
||||||
|
anchor={cords}
|
||||||
|
position="Bottom"
|
||||||
|
align="Start"
|
||||||
|
offset={4}
|
||||||
|
content={
|
||||||
|
<FocusTrap
|
||||||
|
focusTrapOptions={{
|
||||||
|
initialFocus: false,
|
||||||
|
onDeactivate: close,
|
||||||
|
clickOutsideDeactivates: true,
|
||||||
|
escapeDeactivates: stopPropagation,
|
||||||
|
isKeyForward: (evt: KeyboardEvent) => isKeyHotkey('arrowdown', evt),
|
||||||
|
isKeyBackward: (evt: KeyboardEvent) => isKeyHotkey('arrowup', evt),
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Menu>
|
||||||
|
<div style={{ padding: config.space.S100 }}>
|
||||||
|
<MenuItem
|
||||||
|
variant="Surface"
|
||||||
|
fill="None"
|
||||||
|
size="300"
|
||||||
|
radii="300"
|
||||||
|
onClick={() => {
|
||||||
|
copyToClipboard(userId);
|
||||||
|
setCopied();
|
||||||
|
close();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text size="B300">Copy User ID</Text>
|
||||||
|
</MenuItem>
|
||||||
|
<MenuItem
|
||||||
|
variant="Surface"
|
||||||
|
fill="None"
|
||||||
|
size="300"
|
||||||
|
radii="300"
|
||||||
|
onClick={() => {
|
||||||
|
copyToClipboard(getMatrixToUser(userId));
|
||||||
|
setCopied();
|
||||||
|
close();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Text size="B300">Copy User Link</Text>
|
||||||
|
</MenuItem>
|
||||||
|
</div>
|
||||||
|
</Menu>
|
||||||
|
</FocusTrap>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Chip
|
||||||
|
variant={copied ? 'Success' : 'SurfaceVariant'}
|
||||||
|
radii="Pill"
|
||||||
|
before={
|
||||||
|
cords ? (
|
||||||
|
<Icon size="50" src={Icons.ChevronBottom} />
|
||||||
|
) : (
|
||||||
|
<Icon size="50" src={copied ? Icons.Check : Icons.Link} />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
onClick={open}
|
||||||
|
aria-pressed={!!cords}
|
||||||
|
>
|
||||||
|
<Text size="B300" truncate>
|
||||||
|
Share
|
||||||
|
</Text>
|
||||||
|
</Chip>
|
||||||
|
</PopOut>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
type MutualRoomsData = {
|
type MutualRoomsData = {
|
||||||
rooms: Room[];
|
rooms: Room[];
|
||||||
spaces: Room[];
|
spaces: Room[];
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import { useMediaAuthentication } from '../../hooks/useMediaAuthentication';
|
||||||
import { usePowerLevels, usePowerLevelsAPI } from '../../hooks/usePowerLevels';
|
import { usePowerLevels, usePowerLevelsAPI } from '../../hooks/usePowerLevels';
|
||||||
import { useRoom } from '../../hooks/useRoom';
|
import { useRoom } from '../../hooks/useRoom';
|
||||||
import { useUserPresence } from '../../hooks/useUserPresence';
|
import { useUserPresence } from '../../hooks/useUserPresence';
|
||||||
import { MutualRoomsChip, ServerChip } from './UserChips';
|
import { MutualRoomsChip, ServerChip, ShareChip } from './UserChips';
|
||||||
import { AsyncStatus, useAsyncCallback } from '../../hooks/useAsyncCallback';
|
import { AsyncStatus, useAsyncCallback } from '../../hooks/useAsyncCallback';
|
||||||
import { createDM } from '../../../client/action/room';
|
import { createDM } from '../../../client/action/room';
|
||||||
import { hasDevices } from '../../../util/matrixUtil';
|
import { hasDevices } from '../../../util/matrixUtil';
|
||||||
|
|
@ -105,6 +105,7 @@ export function UserRoomProfile({ userId }: UserRoomProfileProps) {
|
||||||
)}
|
)}
|
||||||
<Box alignItems="Center" gap="200" wrap="Wrap">
|
<Box alignItems="Center" gap="200" wrap="Wrap">
|
||||||
{server && <ServerChip server={server} />}
|
{server && <ServerChip server={server} />}
|
||||||
|
<ShareChip userId={userId} />
|
||||||
<PowerChip userId={userId} />
|
<PowerChip userId={userId} />
|
||||||
<MutualRoomsChip userId={userId} />
|
<MutualRoomsChip userId={userId} />
|
||||||
</Box>
|
</Box>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue