Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Showing
with 1216 additions and 668 deletions
import classNames from 'classnames'; import { X, Crown } from "@styled-icons/boxicons-regular";
import { observer } from "mobx-react-lite";
import { Presence } from "revolt-api/types/Users";
import { Channel } from "revolt.js/dist/maps/Channels";
import { User } from "revolt.js/dist/maps/Users";
import styles from "./Item.module.scss"; import styles from "./Item.module.scss";
import Tooltip from '../../common/Tooltip'; import classNames from "classnames";
import IconButton from '../../ui/IconButton'; import { attachContextMenu } from "preact-context-menu";
import { Localizer, Text } from "preact-i18n"; import { Localizer, Text } from "preact-i18n";
import { X, Crown } from "@styled-icons/boxicons-regular";
import { Children } from "../../../types/Preact";
import UserIcon from '../../common/user/UserIcon';
import ChannelIcon from '../../common/ChannelIcon';
import UserStatus from '../../common/user/UserStatus';
import { attachContextMenu } from 'preact-context-menu';
import { Channels, Users } from "revolt.js/dist/api/objects";
import { isTouchscreenDevice } from "../../../lib/isTouchscreenDevice"; import { isTouchscreenDevice } from "../../../lib/isTouchscreenDevice";
import { useIntermediate } from '../../../context/intermediate/Intermediate'; import { stopPropagation } from "../../../lib/stopPropagation";
import { stopPropagation } from '../../../lib/stopPropagation';
type CommonProps = Omit<JSX.HTMLAttributes<HTMLDivElement>, 'children' | 'as'> & { import { useIntermediate } from "../../../context/intermediate/Intermediate";
active?: boolean
alert?: 'unread' | 'mention' import ChannelIcon from "../../common/ChannelIcon";
alertCount?: number import Tooltip from "../../common/Tooltip";
} import UserIcon from "../../common/user/UserIcon";
import { Username } from "../../common/user/UserShort";
import UserStatus from "../../common/user/UserStatus";
import IconButton from "../../ui/IconButton";
import { Children } from "../../../types/Preact";
type CommonProps = Omit<
JSX.HTMLAttributes<HTMLDivElement>,
"children" | "as"
> & {
active?: boolean;
alert?: "unread" | "mention";
alertCount?: number;
};
type UserProps = CommonProps & { type UserProps = CommonProps & {
user: Users.User, user: User;
context?: Channels.Channel, context?: Channel;
channel?: Channels.DirectMessageChannel channel?: Channel;
} };
export function UserButton(props: UserProps) { export const UserButton = observer((props: UserProps) => {
const { active, alert, alertCount, user, context, channel, ...divProps } = props; const { active, alert, alertCount, user, context, channel, ...divProps } =
props;
const { openScreen } = useIntermediate(); const { openScreen } = useIntermediate();
return ( return (
<div {...divProps} <div
{...divProps}
className={classNames(styles.item, styles.user)} className={classNames(styles.item, styles.user)}
data-active={active} data-active={active}
data-alert={typeof alert === 'string'} data-alert={typeof alert === "string"}
data-online={typeof channel !== 'undefined' || (user.online && user.status?.presence !== Users.Presence.Invisible)} data-online={
onContextMenu={attachContextMenu('Menu', { typeof channel !== "undefined" ||
(user.online && user.status?.presence !== Presence.Invisible)
}
onContextMenu={attachContextMenu("Menu", {
user: user._id, user: user._id,
channel: channel?._id, channel: channel?._id,
unread: alert, unread: alert,
contextualChannel: context?._id contextualChannel: context?._id,
})}> })}>
<UserIcon className={styles.avatar} target={user} size={32} status /> <UserIcon
className={styles.avatar}
target={user}
size={32}
status
/>
<div className={styles.name}> <div className={styles.name}>
<div>{user.username}</div> <div>
<Username user={user} />
</div>
{ {
<div className={styles.subText}> <div className={styles.subText}>
{ channel?.last_message && alert ? ( {channel?.last_message && alert ? (
channel.last_message.short (channel.last_message as { short: string }).short
) : ( ) : (
<UserStatus user={user} /> <UserStatus user={user} />
) } )}
</div> </div>
} }
</div> </div>
<div className={styles.button}> <div className={styles.button}>
{ context?.channel_type === "Group" && {context?.channel_type === "Group" &&
context.owner === user._id && ( context.owner_id === user._id && (
<Localizer> <Localizer>
<Tooltip <Tooltip
content={ content={<Text id="app.main.groups.owner" />}>
<Text id="app.main.groups.owner" />
}
>
<Crown size={20} /> <Crown size={20} />
</Tooltip> </Tooltip>
</Localizer> </Localizer>
)}
{alert && (
<div className={styles.alert} data-style={alert}>
{alertCount}
</div>
)} )}
{alert && <div className={styles.alert} data-style={alert}>{ alertCount }</div>} {!isTouchscreenDevice && channel && (
{ !isTouchscreenDevice && channel && <IconButton
<IconButton className={styles.icon} className={styles.icon}
onClick={e => stopPropagation(e) && openScreen({ id: 'special_prompt', type: 'close_dm', target: channel })}> onClick={(e) =>
stopPropagation(e) &&
openScreen({
id: "special_prompt",
type: "close_dm",
target: channel,
})
}>
<X size={24} /> <X size={24} />
</IconButton> </IconButton>
} )}
</div> </div>
</div> </div>
) );
} });
type ChannelProps = CommonProps & { type ChannelProps = CommonProps & {
channel: Channels.Channel & { unread?: string }, channel: Channel & { unread?: string };
user?: Users.User user?: User;
compact?: boolean compact?: boolean;
} };
export function ChannelButton(props: ChannelProps) { export const ChannelButton = observer((props: ChannelProps) => {
const { active, alert, alertCount, channel, user, compact, ...divProps } = props; const { active, alert, alertCount, channel, user, compact, ...divProps } =
props;
if (channel.channel_type === 'SavedMessages') throw "Invalid channel type."; if (channel.channel_type === "SavedMessages") throw "Invalid channel type.";
if (channel.channel_type === 'DirectMessage') { if (channel.channel_type === "DirectMessage") {
if (typeof user === 'undefined') throw "No user provided."; if (typeof user === "undefined") throw "No user provided.";
return <UserButton {...{ active, alert, channel, user }} /> return <UserButton {...{ active, alert, channel, user }} />;
} }
const { openScreen } = useIntermediate(); const { openScreen } = useIntermediate();
return ( return (
<div {...divProps} <div
{...divProps}
data-active={active} data-active={active}
data-alert={typeof alert === 'string'} data-alert={typeof alert === "string"}
aria-label={{}} /*FIXME: ADD ARIA LABEL*/ aria-label={channel.name}
className={classNames(styles.item, { [styles.compact]: compact })} className={classNames(styles.item, { [styles.compact]: compact })}
onContextMenu={attachContextMenu('Menu', { channel: channel._id, unread: typeof channel.unread !== 'undefined' })}> onContextMenu={attachContextMenu("Menu", {
<ChannelIcon className={styles.avatar} target={channel} size={compact ? 24 : 32} /> channel: channel._id,
unread: typeof channel.unread !== "undefined",
})}>
<ChannelIcon
className={styles.avatar}
target={channel}
size={compact ? 24 : 32}
/>
<div className={styles.name}> <div className={styles.name}>
<div>{channel.name}</div> <div>{channel.name}</div>
{ channel.channel_type === 'Group' && {channel.channel_type === "Group" && (
<div className={styles.subText}> <div className={styles.subText}>
{(channel.last_message && alert) ? ( {channel.last_message && alert ? (
channel.last_message.short (channel.last_message as { short: string }).short
) : ( ) : (
<Text <Text
id="quantities.members" id="quantities.members"
plural={channel.recipients.length} plural={channel.recipients!.length}
fields={{ count: channel.recipients.length }} fields={{ count: channel.recipients!.length }}
/> />
)} )}
</div> </div>
} )}
</div> </div>
<div className={styles.button}> <div className={styles.button}>
{alert && <div className={styles.alert} data-style={alert}>{ alertCount }</div>} {alert && (
<div className={styles.alert} data-style={alert}>
{alertCount}
</div>
)}
{!isTouchscreenDevice && channel.channel_type === "Group" && ( {!isTouchscreenDevice && channel.channel_type === "Group" && (
<IconButton <IconButton
className={styles.icon} className={styles.icon}
onClick={() => openScreen({ id: 'special_prompt', type: 'leave_group', target: channel })}> onClick={() =>
openScreen({
id: "special_prompt",
type: "leave_group",
target: channel,
})
}>
<X size={24} /> <X size={24} />
</IconButton> </IconButton>
)} )}
</div> </div>
</div> </div>
) );
} });
type ButtonProps = CommonProps & { type ButtonProps = CommonProps & {
onClick?: () => void onClick?: () => void;
children?: Children children?: Children;
className?: string className?: string;
compact?: boolean compact?: boolean;
} };
export default function ButtonItem(props: ButtonProps) { export default function ButtonItem(props: ButtonProps) {
const { active, alert, alertCount, onClick, className, children, compact, ...divProps } = props; const {
active,
alert,
alertCount,
onClick,
className,
children,
compact,
...divProps
} = props;
return ( return (
<div {...divProps} <div
className={classNames(styles.item, { [styles.compact]: compact, [styles.normal]: !compact }, className)} {...divProps}
className={classNames(
styles.item,
{ [styles.compact]: compact, [styles.normal]: !compact },
className,
)}
onClick={onClick} onClick={onClick}
data-active={active} data-active={active}
data-alert={typeof alert === 'string'}> data-alert={typeof alert === "string"}>
<div className={styles.content}>{ children }</div> <div className={styles.content}>{children}</div>
{alert && <div className={styles.alert} data-style={alert}>{ alertCount }</div>} {alert && (
<div className={styles.alert} data-style={alert}>
{alertCount}
</div>
)}
</div> </div>
) );
} }
import { Text } from "preact-i18n"; import { Text } from "preact-i18n";
import Banner from "../../ui/Banner";
import { useContext } from "preact/hooks"; import { useContext } from "preact/hooks";
import { ClientStatus, StatusContext } from "../../../context/revoltjs/RevoltClient";
import {
ClientStatus,
StatusContext,
} from "../../../context/revoltjs/RevoltClient";
import Banner from "../../ui/Banner";
export default function ConnectionStatus() { export default function ConnectionStatus() {
const status = useContext(StatusContext); const status = useContext(StatusContext);
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
display: flex; display: flex;
padding: 0 8px; padding: 0 8px;
user-select: none; user-select: none;
border-radius: 6px;
margin-bottom: 2px; margin-bottom: 2px;
border-radius: var(--border-radius);
gap: 8px; gap: 8px;
align-items: center; align-items: center;
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
height: 42px; height: 42px;
} }
&.compact { &.compact { /* TOFIX: Introduce two separate compact items, one for settings, other for channels. */
height: 32px; height: 32px;
} }
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
transition: color .1s ease-in-out; transition: color .1s ease-in-out;
&.content { &.content {
gap: 8px; gap: 10px;
flex-grow: 1; flex-grow: 1;
min-width: 0; min-width: 0;
display: flex; display: flex;
...@@ -147,14 +147,18 @@ ...@@ -147,14 +147,18 @@
@media (pointer: coarse) { @media (pointer: coarse) {
.item { .item {
height: 55px; height: 40px;
&.compact { &.compact {
height: 50px; height: var(--bottom-navigation-height);
div > svg { > div {
height: 22px; gap: 20px;
width: 22px;
> svg {
height: 24px;
width: 24px;
}
} }
} }
} }
......
import { Localizer, Text } from "preact-i18n"; import {
Home,
UserDetail,
Wrench,
Notepad,
} from "@styled-icons/boxicons-solid";
import { observer } from "mobx-react-lite";
import { Link, Redirect, useLocation, useParams } from "react-router-dom";
import { RelationshipStatus } from "revolt-api/types/Users";
import { Text } from "preact-i18n";
import { useContext, useEffect } from "preact/hooks"; import { useContext, useEffect } from "preact/hooks";
import { Home, UserDetail, Wrench, Notepad } from "@styled-icons/boxicons-solid";
import Category from '../../ui/Category'; import ConditionalLink from "../../../lib/ConditionalLink";
import PaintCounter from "../../../lib/PaintCounter"; import PaintCounter from "../../../lib/PaintCounter";
import UserHeader from "../../common/user/UserHeader"; import { isTouchscreenDevice } from "../../../lib/isTouchscreenDevice";
import { Channels } from "revolt.js/dist/api/objects";
import { dispatch } from "../../../redux";
import { connectState } from "../../../redux/connector"; import { connectState } from "../../../redux/connector";
import ConnectionStatus from '../items/ConnectionStatus';
import { WithDispatcher } from "../../../redux/reducers";
import { Unreads } from "../../../redux/reducers/unreads"; import { Unreads } from "../../../redux/reducers/unreads";
import ConditionalLink from "../../../lib/ConditionalLink";
import { mapChannelWithUnread, useUnreads } from "./common";
import { Users as UsersNS } from 'revolt.js/dist/api/objects';
import ButtonItem, { ChannelButton } from '../items/ButtonItem';
import { AppContext } from "../../../context/revoltjs/RevoltClient";
import { isTouchscreenDevice } from "../../../lib/isTouchscreenDevice";
import { GenericSidebarBase, GenericSidebarList } from "../SidebarBase";
import { Link, Redirect, useLocation, useParams } from "react-router-dom";
import { useIntermediate } from "../../../context/intermediate/Intermediate"; import { useIntermediate } from "../../../context/intermediate/Intermediate";
import { useDMs, useForceUpdate, useUsers } from "../../../context/revoltjs/hooks"; import { AppContext } from "../../../context/revoltjs/RevoltClient";
import Category from "../../ui/Category";
import placeholderSVG from "../items/placeholder.svg"; import placeholderSVG from "../items/placeholder.svg";
import { mapChannelWithUnread, useUnreads } from "./common";
type Props = WithDispatcher & { import { GenericSidebarBase, GenericSidebarList } from "../SidebarBase";
import ButtonItem, { ChannelButton } from "../items/ButtonItem";
import ConnectionStatus from "../items/ConnectionStatus";
type Props = {
unreads: Unreads; unreads: Unreads;
} };
function HomeSidebar(props: Props) { const HomeSidebar = observer((props: Props) => {
const { pathname } = useLocation(); const { pathname } = useLocation();
const client = useContext(AppContext); const client = useContext(AppContext);
const { channel } = useParams<{ channel: string }>(); const { channel } = useParams<{ channel: string }>();
const { openScreen } = useIntermediate(); const { openScreen } = useIntermediate();
const ctx = useForceUpdate(); const channels = [...client.channels.values()]
const channels = useDMs(ctx); .filter(
(x) =>
x.channel_type === "DirectMessage" ||
x.channel_type === "Group",
)
.map((x) => mapChannelWithUnread(x, props.unreads));
const obj = channels.find(x => x?._id === channel); const obj = client.channels.get(channel);
if (channel && !obj) return <Redirect to="/" />; if (channel && !obj) return <Redirect to="/" />;
if (obj) useUnreads({ ...props, channel: obj }); if (obj) useUnreads({ ...props, channel: obj });
useEffect(() => { useEffect(() => {
if (!channel) return; if (!channel) return;
props.dispatcher({ dispatch({
type: 'LAST_OPENED_SET', type: "LAST_OPENED_SET",
parent: 'home', parent: "home",
child: channel child: channel,
}); });
}, [ channel ]); }, [channel]);
const channelsArr = channels
.filter(x => x.channel_type !== 'SavedMessages')
.map(x => mapChannelWithUnread(x, props.unreads));
const users = useUsers(
(channelsArr as (Channels.DirectMessageChannel | Channels.GroupChannel)[])
.reduce((prev: any, cur) => [ ...prev, ...cur.recipients ], [])
, ctx);
channelsArr.sort((b, a) => a.timestamp.localeCompare(b.timestamp)); channels.sort((b, a) => a.timestamp.localeCompare(b.timestamp));
return ( return (
<GenericSidebarBase padding> <GenericSidebarBase padding>
<UserHeader user={client.user!} />
<ConnectionStatus /> <ConnectionStatus />
<GenericSidebarList> <GenericSidebarList>
<ConditionalLink active={pathname === "/"} to="/">
<ButtonItem active={pathname === "/"}>
<Home size={20} />
<span>
<Text id="app.navigation.tabs.home" />
</span>
</ButtonItem>
</ConditionalLink>
{!isTouchscreenDevice && ( {!isTouchscreenDevice && (
<> <>
<ConditionalLink active={pathname === "/"} to="/"> <ConditionalLink
<ButtonItem active={pathname === "/"}> active={pathname === "/friends"}
<Home size={20} /> to="/friends">
<span><Text id="app.navigation.tabs.home" /></span>
</ButtonItem>
</ConditionalLink>
<ConditionalLink active={pathname === "/friends"} to="/friends">
<ButtonItem <ButtonItem
active={pathname === "/friends"} active={pathname === "/friends"}
alert={ alert={
typeof users.find( typeof [...client.users.values()].find(
user => (user) =>
user?.relationship === user?.relationship ===
UsersNS.Relationship.Incoming RelationshipStatus.Incoming,
) !== "undefined" ? 'unread' : undefined ) !== "undefined"
} ? "unread"
> : undefined
}>
<UserDetail size={20} /> <UserDetail size={20} />
<span><Text id="app.navigation.tabs.friends" /></span> <span>
<Text id="app.navigation.tabs.friends" />
</span>
</ButtonItem> </ButtonItem>
</ConditionalLink> </ConditionalLink>
</> </>
)} )}
<ConditionalLink active={obj?.channel_type === "SavedMessages"} to="/open/saved"> <ConditionalLink
active={obj?.channel_type === "SavedMessages"}
to="/open/saved">
<ButtonItem active={obj?.channel_type === "SavedMessages"}> <ButtonItem active={obj?.channel_type === "SavedMessages"}>
<Notepad size={20} /> <Notepad size={20} />
<span><Text id="app.navigation.tabs.saved" /></span> <span>
<Text id="app.navigation.tabs.saved" />
</span>
</ButtonItem> </ButtonItem>
</ConditionalLink> </ConditionalLink>
{import.meta.env.DEV && ( {import.meta.env.DEV && (
<Link to="/dev"> <Link to="/dev">
<ButtonItem active={pathname === "/dev"}> <ButtonItem active={pathname === "/dev"}>
<Wrench size={20} /> <Wrench size={20} />
<span><Text id="app.navigation.tabs.dev" /></span> <span>
<Text id="app.navigation.tabs.dev" />
</span>
</ButtonItem> </ButtonItem>
</Link> </Link>
)} )}
<Localizer> <Category
<Category text={<Text id="app.main.categories.conversations" />}
text={ action={() =>
( openScreen({
<Text id="app.main.categories.conversations" /> id: "special_input",
) as any type: "create_group",
} })
action={() => openScreen({ id: "special_input", type: "create_group" })} }
/> />
</Localizer> {channels.length === 0 && (
{channelsArr.length === 0 && <img src={placeholderSVG} />} <img src={placeholderSVG} loading="eager" />
{channelsArr.map(x => { )}
{channels.map((x) => {
let user; let user;
if (x.channel_type === 'DirectMessage') { if (x.channel.channel_type === "DirectMessage") {
if (!x.active) return null; if (!x.channel.active) return null;
user = x.channel.recipient;
let recipient = client.channels.getRecipient(x._id);
user = users.find(x => x?._id === recipient);
if (!user) { if (!user) {
console.warn(`Skipped DM ${x._id} because user was missing.`); console.warn(
`Skipped DM ${x.channel._id} because user was missing.`,
);
return null; return null;
} }
} }
return ( return (
<ConditionalLink active={x._id === channel} to={`/channel/${x._id}`}> <ConditionalLink
key={x.channel._id}
active={x.channel._id === channel}
to={`/channel/${x.channel._id}`}>
<ChannelButton <ChannelButton
user={user} user={user}
channel={x} channel={x.channel}
alert={x.unread} alert={x.unread}
alertCount={x.alertCount} alertCount={x.alertCount}
active={x._id === channel} active={x.channel._id === channel}
/> />
</ConditionalLink> </ConditionalLink>
); );
...@@ -146,15 +165,14 @@ function HomeSidebar(props: Props) { ...@@ -146,15 +165,14 @@ function HomeSidebar(props: Props) {
</GenericSidebarList> </GenericSidebarList>
</GenericSidebarBase> </GenericSidebarBase>
); );
}; });
export default connectState( export default connectState(
HomeSidebar, HomeSidebar,
state => { (state) => {
return { return {
unreads: state.unreads unreads: state.unreads,
}; };
}, },
true, true,
true
); );
import Tooltip from "../../common/Tooltip"; import { Plus } from "@styled-icons/boxicons-regular";
import IconButton from "../../ui/IconButton"; import { observer } from "mobx-react-lite";
import LineDivider from "../../ui/LineDivider"; import { useHistory, useLocation, useParams } from "react-router-dom";
import { mapChannelWithUnread } from "./common"; import { RelationshipStatus } from "revolt-api/types/Users";
import styled, { css } from "styled-components"; import styled, { css } from "styled-components";
import ServerIcon from "../../common/ServerIcon";
import { Children } from "../../../types/Preact"; import { attachContextMenu } from "preact-context-menu";
import UserIcon from "../../common/user/UserIcon";
import ConditionalLink from "../../../lib/ConditionalLink";
import PaintCounter from "../../../lib/PaintCounter"; import PaintCounter from "../../../lib/PaintCounter";
import { Plus } from "@styled-icons/boxicons-regular"; import { isTouchscreenDevice } from "../../../lib/isTouchscreenDevice";
import { connectState } from "../../../redux/connector"; import { connectState } from "../../../redux/connector";
import { useLocation, useParams } from "react-router-dom";
import { Unreads } from "../../../redux/reducers/unreads";
import ConditionalLink from "../../../lib/ConditionalLink";
import { Channel, Servers } from "revolt.js/dist/api/objects";
import { LastOpened } from "../../../redux/reducers/last_opened"; import { LastOpened } from "../../../redux/reducers/last_opened";
import { isTouchscreenDevice } from "../../../lib/isTouchscreenDevice"; import { Unreads } from "../../../redux/reducers/unreads";
import { attachContextMenu, openContextMenu } from 'preact-context-menu';
import { useIntermediate } from "../../../context/intermediate/Intermediate"; import { useIntermediate } from "../../../context/intermediate/Intermediate";
import { useChannels, useForceUpdate, useSelf, useServers } from "../../../context/revoltjs/hooks"; import { useClient } from "../../../context/revoltjs/RevoltClient";
import ServerIcon from "../../common/ServerIcon";
import Tooltip from "../../common/Tooltip";
import UserHover from "../../common/user/UserHover";
import UserIcon from "../../common/user/UserIcon";
import IconButton from "../../ui/IconButton";
import LineDivider from "../../ui/LineDivider";
import { mapChannelWithUnread } from "./common";
import { Children } from "../../../types/Preact";
function Icon({ children, unread, size }: { children: Children, unread?: 'mention' | 'unread', size: number }) { function Icon({
children,
unread,
size,
}: {
children: Children;
unread?: "mention" | "unread";
size: number;
}) {
return ( return (
<svg <svg width={size} height={size} aria-hidden="true" viewBox="0 0 32 32">
width={size}
height={size}
aria-hidden="true"
viewBox="0 0 32 32"
>
<use href="#serverIndicator" /> <use href="#serverIndicator" />
<foreignObject x="0" y="0" width="32" height="32" mask={ unread ? "url(#server)" : undefined }> <foreignObject
{ children } x="0"
y="0"
width="32"
height="32"
mask={unread ? "url(#server)" : undefined}>
{children}
</foreignObject> </foreignObject>
{unread === 'unread' && ( {unread === "unread" && (
<circle <circle cx="27" cy="5" r="5" fill={"white"} />
cx="27"
cy="5"
r="5"
fill={"white"}
/>
)} )}
{unread === 'mention' && ( {unread === "mention" && (
<circle <circle cx="27" cy="5" r="5" fill={"var(--error)"} />
cx="27"
cy="5"
r="5"
fill={"red"}
/>
)} )}
</svg> </svg>
) );
} }
const ServersBase = styled.div` const ServersBase = styled.div`
width: 56px; width: 56px;
height: 100%; height: 100%;
padding-left: 2px;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
${ isTouchscreenDevice && css` ${isTouchscreenDevice &&
css`
padding-bottom: 50px; padding-bottom: 50px;
` } `}
`; `;
const ServerList = styled.div` const ServerList = styled.div`
flex-grow: 1; flex-grow: 1;
display: flex; display: flex;
overflow-y: scroll; overflow-y: scroll;
padding-bottom: 48px; padding-bottom: 20px;
/*width: 58px;*/
flex-direction: column; flex-direction: column;
// border-right: 2px solid var(--accent);
scrollbar-width: none; scrollbar-width: none;
...@@ -79,24 +87,29 @@ const ServerList = styled.div` ...@@ -79,24 +87,29 @@ const ServerList = styled.div`
&::-webkit-scrollbar { &::-webkit-scrollbar {
width: 0px; width: 0px;
} }
/*${isTouchscreenDevice &&
css`
width: 58px;
`}*/
`; `;
const ServerEntry = styled.div<{ active: boolean, home?: boolean }>` const ServerEntry = styled.div<{ active: boolean; home?: boolean }>`
height: 58px; height: 58px;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: flex-end;
> * { :focus {
// outline: 1px solid red; outline: 3px solid blue;
} }
> div { > div {
width: 46px; height: 42px;
height: 46px; padding-inline-start: 6px;
display: grid; display: grid;
place-items: center; place-items: center;
border-start-start-radius: 50%; border-start-start-radius: 50%;
border-end-start-radius: 50%; border-end-start-radius: 50%;
...@@ -104,154 +117,220 @@ const ServerEntry = styled.div<{ active: boolean, home?: boolean }>` ...@@ -104,154 +117,220 @@ const ServerEntry = styled.div<{ active: boolean, home?: boolean }>`
transform: translateY(1px); transform: translateY(1px);
} }
${ props => props.active && css` ${(props) =>
background: var(--sidebar-active); props.active &&
&:active { css`
transform: none; &:active {
} transform: none;
` } }
`}
} }
span { > span {
width: 6px; width: 0;
height: 46px; display: relative;
${ props => props.active && css`
background-color: var(--sidebar-active);
&::before, &::after {
// outline: 1px solid blue;
}
&::before, &::after { ${(props) =>
content: ""; !props.active &&
display: block; css`
position: relative; display: none;
`}
width: 31px;
height: 72px;
margin-top: -72px;
margin-left: -25px;
z-index: -1;
background-color: var(--background);
border-bottom-right-radius: 32px;
box-shadow: 0 32px 0 0 var(--sidebar-active);
}
&::after { svg {
transform: scaleY(-1) translateY(-118px); margin-top: 5px;
} pointer-events: none;
` } // outline: 1px solid red;
}
} }
${ props => (!props.active || props.home) && css` ${(props) =>
cursor: pointer; (!props.active || props.home) &&
` } css`
cursor: pointer;
`}
`; `;
function Swoosh() {
return (
<span>
<svg
width="54"
height="106"
viewBox="0 0 54 106"
xmlns="http://www.w3.org/2000/svg">
<path
d="M54 53C54 67.9117 41.9117 80 27 80C12.0883 80 0 67.9117 0 53C0 38.0883 12.0883 26 27 26C41.9117 26 54 38.0883 54 53Z"
fill="var(--sidebar-active)"
/>
<path
d="M27 80C4.5 80 54 53 54 53L54.0001 106C54.0001 106 49.5 80 27 80Z"
fill="var(--sidebar-active)"
/>
<path
d="M27 26C4.5 26 54 53 54 53L53.9999 0C53.9999 0 49.5 26 27 26Z"
fill="var(--sidebar-active)"
/>
</svg>
</span>
);
}
interface Props { interface Props {
unreads: Unreads; unreads: Unreads;
lastOpened: LastOpened; lastOpened: LastOpened;
} }
export function ServerListSidebar({ unreads, lastOpened }: Props) { export const ServerListSidebar = observer(({ unreads, lastOpened }: Props) => {
const ctx = useForceUpdate(); const client = useClient();
const self = useSelf(ctx);
const activeServers = useServers(undefined, ctx) as Servers.Server[]; const { server: server_id } = useParams<{ server?: string }>();
const channels = (useChannels(undefined, ctx) as Channel[]) const server = server_id ? client.servers.get(server_id) : undefined;
.map(x => mapChannelWithUnread(x, unreads)); const activeServers = [...client.servers.values()];
const channels = [...client.channels.values()].map((x) =>
const unreadChannels = channels.filter(x => x.unread) mapChannelWithUnread(x, unreads),
.map(x => x._id); );
const servers = activeServers.map(server => { const unreadChannels = channels
.filter((x) => x.unread)
.map((x) => x.channel?._id);
const servers = activeServers.map((server) => {
let alertCount = 0; let alertCount = 0;
for (let id of server.channels) { for (const id of server.channel_ids) {
let channel = channels.find(x => x._id === id); const channel = channels.find((x) => x.channel?._id === id);
if (channel?.alertCount) { if (channel?.alertCount) {
alertCount += channel.alertCount; alertCount += channel.alertCount;
} }
} }
return { return {
...server, server,
unread: (typeof server.channels.find(x => unreadChannels.includes(x)) !== 'undefined' ? unread: (typeof server.channel_ids.find((x) =>
( alertCount > 0 ? 'mention' : 'unread' ) : undefined) as 'mention' | 'unread' | undefined, unreadChannels.includes(x),
alertCount ) !== "undefined"
} ? alertCount > 0
? "mention"
: "unread"
: undefined) as "mention" | "unread" | undefined,
alertCount,
};
}); });
const history = useHistory();
const path = useLocation().pathname; const path = useLocation().pathname;
const { server: server_id } = useParams<{ server?: string }>();
const server = servers.find(x => x!._id == server_id);
const { openScreen } = useIntermediate(); const { openScreen } = useIntermediate();
let homeUnread: 'mention' | 'unread' | undefined; let homeUnread: "mention" | "unread" | undefined;
let alertCount = 0; let alertCount = 0;
for (let x of channels) { for (const x of channels) {
if (((x.channel_type === 'DirectMessage' && x.active) || x.channel_type === 'Group') && x.unread) { if (
homeUnread = 'unread'; (x.channel?.channel_type === "DirectMessage"
? x.channel?.active
: x.channel?.channel_type === "Group") &&
x.unread
) {
homeUnread = "unread";
alertCount += x.alertCount ?? 0; alertCount += x.alertCount ?? 0;
} }
} }
if (alertCount > 0) homeUnread = 'mention'; if (
const homeActive = typeof server === 'undefined' && !path.startsWith('/invite'); [...client.users.values()].find(
(x) => x.relationship === RelationshipStatus.Incoming,
)
) {
alertCount++;
}
if (alertCount > 0) homeUnread = "mention";
const homeActive =
typeof server === "undefined" && !path.startsWith("/invite");
return ( return (
<ServersBase> <ServersBase>
<ServerList> <ServerList>
<ConditionalLink active={homeActive} to={lastOpened.home ? `/channel/${lastOpened.home}` : '/'}> <ConditionalLink
active={homeActive}
to={lastOpened.home ? `/channel/${lastOpened.home}` : "/"}>
<ServerEntry home active={homeActive}> <ServerEntry home active={homeActive}>
<div onContextMenu={attachContextMenu('Status')} <Swoosh />
onClick={() => homeActive && openContextMenu("Status")}> <div
<Icon size={42} unread={homeUnread}> onContextMenu={attachContextMenu("Status")}
<UserIcon target={self} size={32} status /> onClick={() =>
</Icon> homeActive && history.push("/settings")
}>
<UserHover user={client.user}>
<Icon size={42} unread={homeUnread}>
<UserIcon
target={client.user}
size={32}
status
hover
/>
</Icon>
</UserHover>
</div> </div>
<span />
</ServerEntry> </ServerEntry>
</ConditionalLink> </ConditionalLink>
<LineDivider /> <LineDivider />
{ {servers.map((entry) => {
servers.map(entry => { const active = entry.server._id === server?._id;
const active = entry!._id === server?._id; const id = lastOpened[entry.server._id];
const id = lastOpened[entry!._id];
return (
return ( <ConditionalLink
<ConditionalLink active={active} to={`/server/${entry!._id}` + (id ? `/channel/${id}` : '')}> key={entry.server._id}
<ServerEntry active={active}
active={active} to={`/server/${entry.server._id}${
onContextMenu={attachContextMenu('Menu', { server: entry!._id })}> id ? `/channel/${id}` : ""
<Tooltip content={entry.name} placement="right"> }`}>
<Icon size={42} unread={entry.unread}> <ServerEntry
<ServerIcon size={32} target={entry} /> active={active}
</Icon> onContextMenu={attachContextMenu("Menu", {
</Tooltip> server: entry.server._id,
<span /> })}>
</ServerEntry> <Swoosh />
</ConditionalLink> <Tooltip
) content={entry.server.name}
}) placement="right">
} <Icon size={42} unread={entry.unread}>
<IconButton onClick={() => openScreen({ id: 'special_input', type: 'create_server' })}> <ServerIcon
size={32}
target={entry.server}
/>
</Icon>
</Tooltip>
</ServerEntry>
</ConditionalLink>
);
})}
<IconButton
onClick={() =>
openScreen({
id: "special_input",
type: "create_server",
})
}>
<Plus size={36} /> <Plus size={36} />
</IconButton> </IconButton>
{/*<IconButton
onClick={() =>
openScreen({
id: "special_input",
type: "create_server",
})
}>
<Compass size={36} />
</IconButton>*/}
<PaintCounter small /> <PaintCounter small />
</ServerList> </ServerList>
</ServersBase> </ServersBase>
) );
} });
export default connectState( export default connectState(ServerListSidebar, (state) => {
ServerListSidebar, return {
state => { unreads: state.unreads,
return { lastOpened: state.lastOpened,
unreads: state.unreads, };
lastOpened: state.lastOpened });
};
}
);
import { observer } from "mobx-react-lite";
import { Redirect, useParams } from "react-router"; import { Redirect, useParams } from "react-router";
import { ChannelButton } from "../items/ButtonItem"; import styled, { css } from "styled-components";
import { Channels } from "revolt.js/dist/api/objects";
import { Unreads } from "../../../redux/reducers/unreads"; import { attachContextMenu } from "preact-context-menu";
import { WithDispatcher } from "../../../redux/reducers"; import { useEffect } from "preact/hooks";
import { useChannels, useForceUpdate, useServer } from "../../../context/revoltjs/hooks";
import { mapChannelWithUnread, useUnreads } from "./common"; import ConditionalLink from "../../../lib/ConditionalLink";
import ConnectionStatus from '../items/ConnectionStatus';
import { connectState } from "../../../redux/connector";
import PaintCounter from "../../../lib/PaintCounter"; import PaintCounter from "../../../lib/PaintCounter";
import styled from "styled-components"; import { isTouchscreenDevice } from "../../../lib/isTouchscreenDevice";
import { attachContextMenu } from 'preact-context-menu';
import { dispatch } from "../../../redux";
import { connectState } from "../../../redux/connector";
import { Unreads } from "../../../redux/reducers/unreads";
import { useClient } from "../../../context/revoltjs/RevoltClient";
import CollapsibleSection from "../../common/CollapsibleSection";
import ServerHeader from "../../common/ServerHeader"; import ServerHeader from "../../common/ServerHeader";
import { useEffect } from "preact/hooks";
import Category from "../../ui/Category"; import Category from "../../ui/Category";
import ConditionalLink from "../../../lib/ConditionalLink"; import { mapChannelWithUnread, useUnreads } from "./common";
import { ChannelButton } from "../items/ButtonItem";
import ConnectionStatus from "../items/ConnectionStatus";
interface Props { interface Props {
unreads: Unreads; unreads: Unreads;
...@@ -26,10 +34,13 @@ const ServerBase = styled.div` ...@@ -26,10 +34,13 @@ const ServerBase = styled.div`
flex-shrink: 0; flex-shrink: 0;
flex-direction: column; flex-direction: column;
background: var(--secondary-background); background: var(--secondary-background);
border-start-start-radius: 8px; border-start-start-radius: 8px;
border-end-start-radius: 8px;
overflow: hidden; overflow: hidden;
${isTouchscreenDevice &&
css`
padding-bottom: 50px;
`}
`; `;
const ServerList = styled.div` const ServerList = styled.div`
...@@ -42,46 +53,47 @@ const ServerList = styled.div` ...@@ -42,46 +53,47 @@ const ServerList = styled.div`
} }
`; `;
function ServerSidebar(props: Props & WithDispatcher) { const ServerSidebar = observer((props: Props) => {
const { server: server_id, channel: channel_id } = useParams<{ server?: string, channel?: string }>(); const client = useClient();
const ctx = useForceUpdate(); const { server: server_id, channel: channel_id } =
useParams<{ server: string; channel?: string }>();
const server = useServer(server_id, ctx); const server = client.servers.get(server_id);
if (!server) return <Redirect to="/" />; if (!server) return <Redirect to="/" />;
const channels = (useChannels(server.channels, ctx) const channel = channel_id ? client.channels.get(channel_id) : undefined;
.filter(entry => typeof entry !== 'undefined') as Readonly<Channels.TextChannel | Channels.VoiceChannel>[])
.map(x => mapChannelWithUnread(x, props.unreads));
const channel = channels.find(x => x?._id === channel_id);
if (channel_id && !channel) return <Redirect to={`/server/${server_id}`} />; if (channel_id && !channel) return <Redirect to={`/server/${server_id}`} />;
if (channel) useUnreads({ ...props, channel }, ctx); if (channel) useUnreads({ ...props, channel });
useEffect(() => { useEffect(() => {
if (!channel_id) return; if (!channel_id) return;
props.dispatcher({ dispatch({
type: 'LAST_OPENED_SET', type: "LAST_OPENED_SET",
parent: server_id!, parent: server_id!,
child: channel_id! child: channel_id!,
}); });
}, [ channel_id ]); }, [channel_id, server_id]);
const uncategorised = new Set(server.channel_ids);
const elements = [];
let uncategorised = new Set(server.channels);
let elements = [];
function addChannel(id: string) { function addChannel(id: string) {
const entry = channels.find(x => x._id === id); const entry = client.channels.get(id);
if (!entry) return; if (!entry) return;
const active = channel?._id === entry._id; const active = channel?._id === entry._id;
return ( return (
<ConditionalLink active={active} to={`/server/${server!._id}/channel/${entry._id}`}> <ConditionalLink
key={entry._id}
active={active}
to={`/server/${server!._id}/channel/${entry._id}`}>
<ChannelButton <ChannelButton
key={entry._id}
channel={entry} channel={entry}
active={active} active={active}
alert={entry.unread} // ! FIXME: pull it out directly
alert={mapChannelWithUnread(entry, props.unreads).unread}
compact compact
/> />
</ConditionalLink> </ConditionalLink>
...@@ -89,38 +101,45 @@ function ServerSidebar(props: Props & WithDispatcher) { ...@@ -89,38 +101,45 @@ function ServerSidebar(props: Props & WithDispatcher) {
} }
if (server.categories) { if (server.categories) {
for (let category of server.categories) { for (const category of server.categories) {
elements.push(<Category text={category.title} />); const channels = [];
for (const id of category.channels) {
for (let id of category.channels) {
uncategorised.delete(id); uncategorised.delete(id);
elements.push(addChannel(id)); channels.push(addChannel(id));
} }
elements.push(
<CollapsibleSection
id={`category_${category.id}`}
defaultValue
summary={<Category text={category.title} />}>
{channels}
</CollapsibleSection>,
);
} }
} }
for (let id of uncategorised) { for (const id of Array.from(uncategorised).reverse()) {
elements.unshift(addChannel(id)); elements.unshift(addChannel(id));
} }
return ( return (
<ServerBase> <ServerBase>
<ServerHeader server={server} ctx={ctx} /> <ServerHeader server={server} />
<ConnectionStatus /> <ConnectionStatus />
<ServerList onContextMenu={attachContextMenu('Menu', { server_list: server._id })}> <ServerList
{ elements } onContextMenu={attachContextMenu("Menu", {
server_list: server._id,
})}>
{elements}
</ServerList> </ServerList>
<PaintCounter small /> <PaintCounter small />
</ServerBase> </ServerBase>
) );
}; });
export default connectState( export default connectState(ServerSidebar, (state) => {
ServerSidebar, return {
state => { unreads: state.unreads,
return { };
unreads: state.unreads });
};
},
true
);
import { Channel } from "revolt.js"; import { reaction } from "mobx";
import { Channel } from "revolt.js/dist/maps/Channels";
import { useLayoutEffect } from "preact/hooks"; import { useLayoutEffect } from "preact/hooks";
import { WithDispatcher } from "../../../redux/reducers";
import { dispatch } from "../../../redux";
import { Unreads } from "../../../redux/reducers/unreads"; import { Unreads } from "../../../redux/reducers/unreads";
import { HookContext, useForceUpdate } from "../../../context/revoltjs/hooks";
type UnreadProps = WithDispatcher & { type UnreadProps = {
channel: Channel; channel: Channel;
unreads: Unreads; unreads: Unreads;
} };
export function useUnreads({ channel, unreads, dispatcher }: UnreadProps, context?: HookContext) {
const ctx = useForceUpdate(context);
export function useUnreads({ channel, unreads }: UnreadProps) {
useLayoutEffect(() => { useLayoutEffect(() => {
function checkUnread(target?: Channel) { function checkUnread(target: Channel) {
if (!target) return; if (!target) return;
if (target._id !== channel._id) return; if (target._id !== channel._id) return;
if (target.channel_type === "SavedMessages" || if (
target.channel_type === "VoiceChannel") return; target.channel_type === "SavedMessages" ||
target.channel_type === "VoiceChannel"
)
return;
const unread = unreads[channel._id]?.last_id; const unread = unreads[channel._id]?.last_id;
if (target.last_message) { if (target.last_message) {
const message = typeof target.last_message === 'string' ? target.last_message : target.last_message._id; const message =
typeof target.last_message === "string"
? target.last_message
: target.last_message._id;
if (!unread || (unread && message.localeCompare(unread) > 0)) { if (!unread || (unread && message.localeCompare(unread) > 0)) {
dispatcher({ dispatch({
type: "UNREADS_MARK_READ", type: "UNREADS_MARK_READ",
channel: channel._id, channel: channel._id,
message message,
}); });
ctx.client.req('PUT', `/channels/${channel._id}/ack/${message}` as '/channels/id/ack/id'); channel.ack(message);
} }
} }
} }
checkUnread(channel); checkUnread(channel);
return reaction(
ctx.client.channels.addListener("mutation", checkUnread); () => channel.last_message,
return () => ctx.client.channels.removeListener("mutation", checkUnread); () => checkUnread(channel),
);
}, [channel, unreads]); }, [channel, unreads]);
} }
export function mapChannelWithUnread(channel: Channel, unreads: Unreads) { export function mapChannelWithUnread(channel: Channel, unreads: Unreads) {
let last_message_id; let last_message_id;
if (channel.channel_type === 'DirectMessage' || channel.channel_type === 'Group') { if (
last_message_id = channel.last_message?._id; channel.channel_type === "DirectMessage" ||
} else if (channel.channel_type === 'TextChannel') { channel.channel_type === "Group"
last_message_id = channel.last_message; ) {
last_message_id = (channel.last_message as { _id: string })?._id;
} else if (channel.channel_type === "TextChannel") {
last_message_id = channel.last_message as string;
} else { } else {
return { ...channel, unread: undefined, alertCount: undefined, timestamp: channel._id }; return {
channel,
unread: undefined,
alertCount: undefined,
timestamp: channel._id,
};
} }
let unread: 'mention' | 'unread' | undefined; let unread: "mention" | "unread" | undefined;
let alertCount: undefined | number; let alertCount: undefined | number;
if (last_message_id && unreads) { if (last_message_id && unreads) {
const u = unreads[channel._id]; const u = unreads[channel._id];
if (u) { if (u) {
if (u.mentions && u.mentions.length > 0) { if (u.mentions && u.mentions.length > 0) {
alertCount = u.mentions.length; alertCount = u.mentions.length;
unread = 'mention'; unread = "mention";
} else if (u.last_id && last_message_id.localeCompare(u.last_id) > 0) { } else if (
unread = 'unread'; u.last_id &&
(last_message_id as string).localeCompare(u.last_id) > 0
) {
unread = "unread";
} }
} else { } else {
unread = 'unread'; unread = "unread";
} }
} }
return { return {
...channel, channel,
timestamp: last_message_id ?? channel._id, timestamp: last_message_id ?? channel._id,
unread, unread,
alertCount alertCount,
}; };
} }
/* eslint-disable react-hooks/rules-of-hooks */
import { useRenderState } from "../../../lib/renderer/Singleton"; import { useRenderState } from "../../../lib/renderer/Singleton";
interface Props { interface Props {
...@@ -6,7 +7,7 @@ interface Props { ...@@ -6,7 +7,7 @@ interface Props {
export function ChannelDebugInfo({ id }: Props) { export function ChannelDebugInfo({ id }: Props) {
if (process.env.NODE_ENV !== "development") return null; if (process.env.NODE_ENV !== "development") return null;
let view = useRenderState(id); const view = useRenderState(id);
if (!view) return null; if (!view) return null;
return ( return (
...@@ -16,21 +17,24 @@ export function ChannelDebugInfo({ id }: Props) { ...@@ -16,21 +17,24 @@ export function ChannelDebugInfo({ id }: Props) {
display: "block", display: "block",
fontSize: "12px", fontSize: "12px",
textTransform: "uppercase", textTransform: "uppercase",
fontWeight: "600" fontWeight: "600",
}} }}>
>
Channel Info Channel Info
</span> </span>
<p style={{ fontSize: "10px", userSelect: "text" }}> <p style={{ fontSize: "10px", userSelect: "text" }}>
State: <b>{ view.type }</b> <br /> State: <b>{view.type}</b> <br />
{ view.type === 'RENDER' && view.messages.length > 0 && {view.type === "RENDER" && view.messages.length > 0 && (
<> <>
Start: <b>{view.messages[0]._id}</b> <br /> Start: <b>{view.messages[0]._id}</b> <br />
End: <b>{view.messages[view.messages.length - 1]._id}</b> <br /> End:{" "}
<b>
{view.messages[view.messages.length - 1]._id}
</b>{" "}
<br />
At Top: <b>{view.atTop ? "Yes" : "No"}</b> <br /> At Top: <b>{view.atTop ? "Yes" : "No"}</b> <br />
At Bottom: <b>{view.atBottom ? "Yes" : "No"}</b> At Bottom: <b>{view.atBottom ? "Yes" : "No"}</b>
</> </>
} )}
</p> </p>
</span> </span>
); );
......
/* eslint-disable react-hooks/rules-of-hooks */
import { observer } from "mobx-react-lite";
import { Link, useParams } from "react-router-dom";
import { Presence } from "revolt-api/types/Users";
import { Channel } from "revolt.js/dist/maps/Channels";
import { Message } from "revolt.js/dist/maps/Messages";
import { Text } from "preact-i18n"; import { Text } from "preact-i18n";
import { useContext, useEffect, useState } from "preact/hooks"; import { useContext, useEffect, useState } from "preact/hooks";
import { User } from "revolt.js"; import { getState } from "../../../redux";
import Category from "../../ui/Category";
import { useParams } from "react-router";
import { UserButton } from "../items/ButtonItem";
import { ChannelDebugInfo } from "./ChannelDebugInfo";
import { Channels, Servers, Users } from "revolt.js/dist/api/objects";
import { GenericSidebarBase, GenericSidebarList } from "../SidebarBase";
import { useIntermediate } from "../../../context/intermediate/Intermediate"; import { useIntermediate } from "../../../context/intermediate/Intermediate";
import { ClientboundNotification } from "revolt.js/dist/websocket/notifications"; import {
import { AppContext, ClientStatus, StatusContext } from "../../../context/revoltjs/RevoltClient"; ClientStatus,
import { HookContext, useChannel, useForceUpdate, useUsers } from "../../../context/revoltjs/hooks"; StatusContext,
useClient,
} from "../../../context/revoltjs/RevoltClient";
import CollapsibleSection from "../../common/CollapsibleSection";
import Button from "../../ui/Button";
import Category from "../../ui/Category";
import InputBox from "../../ui/InputBox";
import Preloader from "../../ui/Preloader";
import placeholderSVG from "../items/placeholder.svg"; import placeholderSVG from "../items/placeholder.svg";
interface Props { import { GenericSidebarBase, GenericSidebarList } from "../SidebarBase";
ctx: HookContext import { UserButton } from "../items/ButtonItem";
} import { ChannelDebugInfo } from "./ChannelDebugInfo";
export default function MemberSidebar(props: { channel?: Channels.Channel }) { export default function MemberSidebar({ channel: obj }: { channel?: Channel }) {
const ctx = useForceUpdate(); const { channel: channel_id } = useParams<{ channel: string }>();
const { channel: cid } = useParams<{ channel: string }>(); const client = useClient();
const channel = props.channel ?? useChannel(cid, ctx); const channel = obj ?? client.channels.get(channel_id);
switch (channel?.channel_type) { switch (channel?.channel_type) {
case 'Group': return <GroupMemberSidebar channel={channel} ctx={ctx} />; case "Group":
case 'TextChannel': return <ServerMemberSidebar channel={channel} ctx={ctx} />; return <GroupMemberSidebar channel={channel} />;
default: return null; case "TextChannel":
return <ServerMemberSidebar channel={channel} />;
default:
return null;
} }
} }
export function GroupMemberSidebar({ channel, ctx }: Props & { channel: Channels.GroupChannel }) { export const GroupMemberSidebar = observer(
const { openScreen } = useIntermediate(); ({ channel }: { channel: Channel }) => {
const users = useUsers(undefined, ctx); const { openScreen } = useIntermediate();
let members = channel.recipients
.map(x => users.find(y => y?._id === x))
.filter(x => typeof x !== "undefined") as User[];
/*const voice = useContext(VoiceContext); const members = channel.recipients?.filter(
(x) => typeof x !== "undefined",
);
/*const voice = useContext(VoiceContext);
const voiceActive = voice.roomId === channel._id; const voiceActive = voice.roomId === channel._id;
let voiceParticipants: User[] = []; let voiceParticipants: User[] = [];
...@@ -53,28 +66,34 @@ export function GroupMemberSidebar({ channel, ctx }: Props & { channel: Channels ...@@ -53,28 +66,34 @@ export function GroupMemberSidebar({ channel, ctx }: Props & { channel: Channels
voiceParticipants.sort((a, b) => a.username.localeCompare(b.username)); voiceParticipants.sort((a, b) => a.username.localeCompare(b.username));
}*/ }*/
members.sort((a, b) => { members?.sort((a, b) => {
// ! FIXME: should probably rewrite all this code // ! FIXME: should probably rewrite all this code
let l = ((a.online && const l =
a.status?.presence !== Users.Presence.Invisible) ?? +(
false) as any | 0; (a!.online && a!.status?.presence !== Presence.Invisible) ??
let r = ((b.online && false
b.status?.presence !== Users.Presence.Invisible) ?? ) | 0;
false) as any | 0; const r =
+(
(b!.online && b!.status?.presence !== Presence.Invisible) ??
false
) | 0;
let n = r - l; const n = r - l;
if (n !== 0) { if (n !== 0) {
return n; return n;
} }
return a.username.localeCompare(b.username); return a!.username.localeCompare(b!.username);
}); });
return ( return (
<GenericSidebarBase> <GenericSidebarBase>
<GenericSidebarList> <GenericSidebarList>
<ChannelDebugInfo id={channel._id} /> <ChannelDebugInfo id={channel._id} />
{/*voiceActive && voiceParticipants.length !== 0 && ( <Search channel={channel} />
{/*voiceActive && voiceParticipants.length !== 0 && (
<Fragment> <Fragment>
<Category <Category
type="members" type="members"
...@@ -99,108 +118,203 @@ export function GroupMemberSidebar({ channel, ctx }: Props & { channel: Channels ...@@ -99,108 +118,203 @@ export function GroupMemberSidebar({ channel, ctx }: Props & { channel: Channels
)} )}
</Fragment> </Fragment>
)*/} )*/}
{!(members.length === 0 /*&& voiceActive*/) && ( <CollapsibleSection
<Category sticky
variant="uniform" id="members"
text={ defaultValue
<span> summary={
<Text id="app.main.categories.members" />{" "} <Category
{channel.recipients.length} variant="uniform"
</span> text={
} <span>
/> <Text id="app.main.categories.members" />{" "}
)} {channel.recipients?.length ?? 0}
{members.length === 0 && /*!voiceActive &&*/ <img src={placeholderSVG} />} </span>
{members.map( }
user => />
user && ( }>
<UserButton {members?.length === 0 && (
key={user._id} <img src={placeholderSVG} loading="eager" />
user={user} )}
context={channel} {members?.map(
onClick={() => openScreen({ id: 'profile', user_id: user._id })} /> (user) =>
) user && (
)} <UserButton
</GenericSidebarList> key={user._id}
</GenericSidebarBase> user={user}
); context={channel!}
} onClick={() =>
openScreen({
id: "profile",
user_id: user._id,
})
}
/>
),
)}
</CollapsibleSection>
</GenericSidebarList>
</GenericSidebarBase>
);
},
);
export const ServerMemberSidebar = observer(
({ channel }: { channel: Channel }) => {
const client = useClient();
const { openScreen } = useIntermediate();
const status = useContext(StatusContext);
export function ServerMemberSidebar({ channel, ctx }: Props & { channel: Channels.TextChannel }) { useEffect(() => {
const [members, setMembers] = useState<Servers.Member[] | undefined>(undefined); if (status === ClientStatus.ONLINE) {
const users = useUsers(members?.map(x => x._id.user) ?? []).filter(x => typeof x !== 'undefined', ctx) as Users.User[]; channel.server!.fetchMembers();
const status = useContext(StatusContext);
const client = useContext(AppContext);
useEffect(() => {
if (status === ClientStatus.ONLINE && typeof members === 'undefined') {
client.servers.members.fetchMembers(channel.server)
.then(members => setMembers(members))
}
}, [ status ]);
// ! FIXME: temporary code
useEffect(() => {
function onPacket(packet: ClientboundNotification) {
if (!members) return;
if (packet.type === 'ServerMemberJoin') {
if (packet.id !== channel.server) return;
setMembers([ ...members, { _id: { server: packet.id, user: packet.user } } ]);
} else if (packet.type === 'ServerMemberLeave') {
if (packet.id !== channel.server) return;
setMembers(members.filter(x => !(x._id.user === packet.user && x._id.server === packet.id)));
} }
} }, [status, channel.server]);
client.addListener('packet', onPacket); const users = [...client.members.keys()]
return () => client.removeListener('packet', onPacket); .map((x) => JSON.parse(x))
}, [ members ]); .filter((x) => x.server === channel.server_id)
.map((y) => client.users.get(y.user)!)
// copy paste from above .filter((z) => typeof z !== "undefined");
users.sort((a, b) => {
// ! FIXME: should probably rewrite all this code // copy paste from above
let l = ((a.online && users.sort((a, b) => {
a.status?.presence !== Users.Presence.Invisible) ?? // ! FIXME: should probably rewrite all this code
false) as any | 0; const l =
let r = ((b.online && +(
b.status?.presence !== Users.Presence.Invisible) ?? (a.online && a.status?.presence !== Presence.Invisible) ??
false) as any | 0; false
) | 0;
let n = r - l; const r =
if (n !== 0) { +(
return n; (b.online && b.status?.presence !== Presence.Invisible) ??
} false
) | 0;
return a.username.localeCompare(b.username);
}); const n = r - l;
if (n !== 0) {
return n;
}
return a.username.localeCompare(b.username);
});
return (
<GenericSidebarBase>
<GenericSidebarList>
<ChannelDebugInfo id={channel._id} />
<Search channel={channel} />
<div>{users.length === 0 && <Preloader type="ring" />}</div>
{users.length > 0 && (
<CollapsibleSection
//sticky //will re-add later, need to fix css
id="members"
defaultValue
summary={
<span>
<Text id="app.main.categories.members" />{" "}
{users?.length ?? 0}
</span>
}>
{users.map(
(user) =>
user && (
<UserButton
key={user._id}
user={user}
context={channel}
onClick={() =>
openScreen({
id: "profile",
user_id: user._id,
})
}
/>
),
)}
</CollapsibleSection>
)}
</GenericSidebarList>
</GenericSidebarBase>
);
},
);
function Search({ channel }: { channel: Channel }) {
if (!getState().experiments.enabled?.includes("search")) return null;
type Sort = "Relevance" | "Latest" | "Oldest";
const [sort, setSort] = useState<Sort>("Relevance");
const [query, setV] = useState("");
const [results, setResults] = useState<Message[]>([]);
async function search() {
const data = await channel.searchWithUsers({ query, sort });
setResults(data.messages);
}
return ( return (
<GenericSidebarBase> <CollapsibleSection
<GenericSidebarList> sticky
<ChannelDebugInfo id={channel._id} /> id="search"
<Category defaultValue={false}
variant="uniform" summary={
text={ <>
<span> <Text id="app.main.channel.search.title" /> (BETA)
<Text id="app.main.categories.members" />{" "} </>
{users.length} }>
</span> <div style={{ display: "flex" }}>
{["Relevance", "Latest", "Oldest"].map((key) => (
<Button
key={key}
style={{ flex: 1, minWidth: 0 }}
compact
error={sort === key}
onClick={() => setSort(key as Sort)}>
<Text
id={`app.main.channel.search.sort.${key.toLowerCase()}`}
/>
</Button>
))}
</div>
<InputBox
style={{ width: "100%" }}
onKeyDown={(e) => e.key === "Enter" && search()}
value={query}
onChange={(e) => setV(e.currentTarget.value)}
/>
<div
style={{
display: "flex",
flexDirection: "column",
gap: "4px",
marginTop: "8px",
}}>
{results.map((message) => {
let href = "";
if (channel?.channel_type === "TextChannel") {
href += `/server/${channel.server_id}`;
} }
/>
{users.length === 0 && <img src={placeholderSVG} />} href += `/channel/${message.channel_id}/${message._id}`;
{users.map(
user => return (
user && ( <Link to={href} key={message._id}>
// <LinkProfile user_id={user._id}> <div
<UserButton style={{
key={user._id} margin: "2px",
user={user} padding: "6px",
context={channel} background: "var(--primary-background)",
/> }}>
// </LinkProfile> <b>@{message.author?.username}</b>
) <br />
)} {message.content}
</GenericSidebarList> </div>
</GenericSidebarBase> </Link>
);
})}
</div>
</CollapsibleSection>
); );
} }
import styled, { css } from "styled-components"; import styled, { css } from "styled-components";
interface Props { interface Props {
readonly compact?: boolean;
readonly accent?: boolean;
readonly contrast?: boolean; readonly contrast?: boolean;
readonly plain?: boolean;
readonly error?: boolean; readonly error?: boolean;
readonly gold?: boolean;
readonly iconbutton?: boolean;
} }
export type ButtonProps = Props &
Omit<JSX.HTMLAttributes<HTMLButtonElement>, "as">;
export default styled.button<Props>` export default styled.button<Props>`
z-index: 1; z-index: 1;
padding: 8px; display: flex;
font-size: 16px; height: 38px;
text-align: center; min-width: 96px;
font-family: 'Open Sans', sans-serif; align-items: center;
justify-content: center;
padding: 2px 16px;
font-size: 0.875rem;
font-family: inherit;
font-weight: 500;
transition: 0.2s ease opacity; transition: 0.2s ease opacity;
transition: 0.2s ease background-color; transition: 0.2s ease background-color;
...@@ -18,7 +31,7 @@ export default styled.button<Props>` ...@@ -18,7 +31,7 @@ export default styled.button<Props>`
background: var(--primary-background); background: var(--primary-background);
color: var(--foreground); color: var(--foreground);
border-radius: 6px; border-radius: var(--border-radius);
cursor: pointer; cursor: pointer;
border: none; border: none;
...@@ -27,6 +40,7 @@ export default styled.button<Props>` ...@@ -27,6 +40,7 @@ export default styled.button<Props>`
} }
&:disabled { &:disabled {
cursor: not-allowed;
background: var(--primary-background); background: var(--primary-background);
} }
...@@ -34,6 +48,47 @@ export default styled.button<Props>` ...@@ -34,6 +48,47 @@ export default styled.button<Props>`
background: var(--secondary-background); background: var(--secondary-background);
} }
${(props) =>
props.compact &&
css`
height: 32px !important;
padding: 2px 12px !important;
font-size: 13px;
`}
${(props) =>
props.iconbutton &&
css`
height: 38px !important;
width: 38px !important;
min-width: unset !important;
`}
${(props) =>
props.accent &&
css`
background: var(--accent) !important;
`}
${(props) =>
props.plain &&
css`
background: transparent !important;
&:hover {
text-decoration: underline;
}
&:disabled {
cursor: not-allowed;
opacity: 0.5;
}
&:active {
background: var(--secondary-background);
}
`}
${(props) => ${(props) =>
props.contrast && props.contrast &&
css` css`
...@@ -45,6 +100,7 @@ export default styled.button<Props>` ...@@ -45,6 +100,7 @@ export default styled.button<Props>`
} }
&:disabled { &:disabled {
cursor: not-allowed;
background: var(--secondary-header); background: var(--secondary-header);
} }
...@@ -57,6 +113,7 @@ export default styled.button<Props>` ...@@ -57,6 +113,7 @@ export default styled.button<Props>`
props.error && props.error &&
css` css`
color: white; color: white;
font-weight: 600;
background: var(--error); background: var(--error);
&:hover { &:hover {
...@@ -65,7 +122,26 @@ export default styled.button<Props>` ...@@ -65,7 +122,26 @@ export default styled.button<Props>`
} }
&:disabled { &:disabled {
cursor: not-allowed;
background: var(--error); background: var(--error);
} }
`} `}
${(props) =>
props.gold &&
css`
color: black;
font-weight: 600;
background: goldenrod;
&:hover {
filter: brightness(1.2);
background: goldenrod;
}
&:disabled {
cursor: not-allowed;
background: goldenrod;
}
`}
`; `;
import { Plus } from "@styled-icons/boxicons-regular";
import styled, { css } from "styled-components"; import styled, { css } from "styled-components";
import { Children } from "../../types/Preact"; import { Children } from "../../types/Preact";
import { Plus } from "@styled-icons/boxicons-regular";
const CategoryBase = styled.div<Pick<Props, 'variant'>>` const CategoryBase = styled.div<Pick<Props, "variant">>`
font-size: 12px; font-size: 12px;
font-weight: 700; font-weight: 700;
text-transform: uppercase; text-transform: uppercase;
...@@ -11,7 +12,7 @@ const CategoryBase = styled.div<Pick<Props, 'variant'>>` ...@@ -11,7 +12,7 @@ const CategoryBase = styled.div<Pick<Props, 'variant'>>`
padding: 6px 0; padding: 6px 0;
margin-bottom: 4px; margin-bottom: 4px;
white-space: nowrap; white-space: nowrap;
display: flex; display: flex;
align-items: center; align-items: center;
flex-direction: row; flex-direction: row;
...@@ -26,26 +27,29 @@ const CategoryBase = styled.div<Pick<Props, 'variant'>>` ...@@ -26,26 +27,29 @@ const CategoryBase = styled.div<Pick<Props, 'variant'>>`
padding-top: 0; padding-top: 0;
} }
${ props => props.variant === 'uniform' && css` ${(props) =>
padding-top: 6px; props.variant === "uniform" &&
` } css`
padding-top: 6px;
`}
`; `;
type Props = Omit<JSX.HTMLAttributes<HTMLDivElement>, 'children' | 'as'> & { type Props = Omit<
JSX.HTMLAttributes<HTMLDivElement>,
"children" | "as" | "action"
> & {
text: Children; text: Children;
action?: () => void; action?: () => void;
variant?: 'default' | 'uniform'; variant?: "default" | "uniform";
} };
export default function Category(props: Props) { export default function Category(props: Props) {
let { text, action, ...otherProps } = props; const { text, action, ...otherProps } = props;
return ( return (
<CategoryBase {...otherProps}> <CategoryBase {...otherProps}>
{text} {text}
{action && ( {action && <Plus size={16} onClick={action} />}
<Plus size={16} onClick={action} />
)}
</CategoryBase> </CategoryBase>
); );
}; }
import { Check } from "@styled-icons/boxicons-regular"; import { Check } from "@styled-icons/boxicons-regular";
import { Children } from "../../types/Preact";
import styled, { css } from "styled-components"; import styled, { css } from "styled-components";
import { Children } from "../../types/Preact";
const CheckboxBase = styled.label` const CheckboxBase = styled.label`
gap: 4px; gap: 4px;
z-index: 1; z-index: 1;
padding: 4px;
display: flex; display: flex;
border-radius: 4px; margin-top: 20px;
align-items: center; align-items: center;
border-radius: var(--border-radius);
cursor: pointer; cursor: pointer;
font-size: 18px; font-size: 18px;
...@@ -16,17 +17,11 @@ const CheckboxBase = styled.label` ...@@ -16,17 +17,11 @@ const CheckboxBase = styled.label`
transition: 0.2s ease all; transition: 0.2s ease all;
p {
margin: 0;
}
input { input {
display: none; display: none;
} }
&:hover { &:hover {
background: var(--secondary-background);
.check { .check {
background: var(--background); background: var(--background);
} }
...@@ -34,7 +29,7 @@ const CheckboxBase = styled.label` ...@@ -34,7 +29,7 @@ const CheckboxBase = styled.label`
&[disabled] { &[disabled] {
opacity: 0.5; opacity: 0.5;
cursor: unset; cursor: not-allowed;
&:hover { &:hover {
background: unset; background: unset;
...@@ -43,15 +38,15 @@ const CheckboxBase = styled.label` ...@@ -43,15 +38,15 @@ const CheckboxBase = styled.label`
`; `;
const CheckboxContent = styled.span` const CheckboxContent = styled.span`
flex-grow: 1;
display: flex; display: flex;
flex-grow: 1;
font-size: 1rem; font-size: 1rem;
font-weight: 600; font-weight: 600;
flex-direction: column; flex-direction: column;
`; `;
const CheckboxDescription = styled.span` const CheckboxDescription = styled.span`
font-size: 0.8em; font-size: 0.75rem;
font-weight: 400; font-weight: 400;
color: var(--secondary-foreground); color: var(--secondary-foreground);
`; `;
...@@ -62,9 +57,9 @@ const Checkmark = styled.div<{ checked: boolean }>` ...@@ -62,9 +57,9 @@ const Checkmark = styled.div<{ checked: boolean }>`
height: 24px; height: 24px;
display: grid; display: grid;
flex-shrink: 0; flex-shrink: 0;
border-radius: 4px;
place-items: center; place-items: center;
transition: 0.2s ease all; transition: 0.2s ease all;
border-radius: var(--border-radius);
background: var(--secondary-background); background: var(--secondary-background);
svg { svg {
......
import { useRef } from "preact/hooks"; import { Check } from "@styled-icons/boxicons-regular";
import { Check, Pencil } from "@styled-icons/boxicons-regular"; import { Palette } from "@styled-icons/boxicons-solid";
import styled, { css } from "styled-components"; import styled, { css } from "styled-components";
import { RefObject } from "preact";
import { useRef } from "preact/hooks";
interface Props { interface Props {
value: string; value: string;
onChange: (value: string) => void; onChange: (value: string) => void;
...@@ -31,21 +34,40 @@ const presets = [ ...@@ -31,21 +34,40 @@ const presets = [
]; ];
const SwatchesBase = styled.div` const SwatchesBase = styled.div`
gap: 8px; /*gap: 8px;*/
display: flex; display: flex;
input { input {
width: 0;
height: 0;
top: 72px;
opacity: 0; opacity: 0;
margin-top: 44px; padding: 0;
position: absolute; border: 0;
position: relative;
pointer-events: none; pointer-events: none;
} }
.overlay {
position: relative;
width: 0;
div {
width: 8px;
height: 68px;
background: linear-gradient(
to right,
var(--primary-background),
transparent
);
}
}
`; `;
const Swatch = styled.div<{ type: "small" | "large"; colour: string }>` const Swatch = styled.div<{ type: "small" | "large"; colour: string }>`
flex-shrink: 0; flex-shrink: 0;
cursor: pointer; cursor: pointer;
border-radius: 4px; border-radius: var(--border-radius);
background-color: ${(props) => props.colour}; background-color: ${(props) => props.colour};
display: grid; display: grid;
...@@ -80,32 +102,39 @@ const Rows = styled.div` ...@@ -80,32 +102,39 @@ const Rows = styled.div`
gap: 8px; gap: 8px;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
overflow: auto;
padding-bottom: 4px;
> div { > div {
gap: 8px; gap: 8px;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
padding-inline-start: 8px;
} }
`; `;
export default function ColourSwatches({ value, onChange }: Props) { export default function ColourSwatches({ value, onChange }: Props) {
const ref = useRef<HTMLInputElement>(); const ref = useRef<HTMLInputElement>() as RefObject<HTMLInputElement>;
return ( return (
<SwatchesBase> <SwatchesBase>
<Swatch
colour={value}
type="large"
onClick={() => ref.current.click()}
>
<Pencil size={32} />
</Swatch>
<input <input
type="color" type="color"
value={value} value={value}
ref={ref} ref={ref}
onChange={(ev) => onChange(ev.currentTarget.value)} onChange={(ev) => onChange(ev.currentTarget.value)}
/> />
<Swatch
colour={value}
type="large"
onClick={() => ref.current?.click()}>
<Palette size={32} />
</Swatch>
<div class="overlay">
<div />
</div>
<Rows> <Rows>
{presets.map((row, i) => ( {presets.map((row, i) => (
<div key={i}> <div key={i}>
...@@ -114,11 +143,8 @@ export default function ColourSwatches({ value, onChange }: Props) { ...@@ -114,11 +143,8 @@ export default function ColourSwatches({ value, onChange }: Props) {
colour={swatch} colour={swatch}
type="small" type="small"
key={i} key={i}
onClick={() => onChange(swatch)} onClick={() => onChange(swatch)}>
> {swatch === value && <Check size={22} />}
{swatch === value && (
<Check size={18} />
)}
</Swatch> </Swatch>
))} ))}
</div> </div>
......
import styled from "styled-components"; import styled from "styled-components";
export default styled.select` export default styled.select`
padding: 8px; width: 100%;
border-radius: 2px; padding: 10px;
cursor: pointer;
border-radius: var(--border-radius);
font-family: inherit;
font-size: var(--text-size);
color: var(--secondary-foreground); color: var(--secondary-foreground);
background: var(--secondary-background); background: var(--secondary-background);
border: none; border: none;
outline: 2px solid transparent; outline: 2px solid transparent;
transition: box-shadow 0.2s ease-in-out;
transition: outline-color 0.2s ease-in-out; transition: outline-color 0.2s ease-in-out;
&:focus { &:focus {
outline-color: var(--accent); box-shadow: 0 0 0 1.5pt var(--accent);
} }
`; `;
import dayjs from "dayjs";
import styled, { css } from "styled-components"; import styled, { css } from "styled-components";
import { dayjs } from "../../context/Locale";
const Base = styled.div<{ unread?: boolean }>` const Base = styled.div<{ unread?: boolean }>`
height: 0; height: 0;
display: flex; display: flex;
...@@ -11,16 +12,19 @@ const Base = styled.div<{ unread?: boolean }>` ...@@ -11,16 +12,19 @@ const Base = styled.div<{ unread?: boolean }>`
time { time {
margin-top: -2px; margin-top: -2px;
font-size: .6875rem; font-size: 0.6875rem;
line-height: .6875rem; line-height: 0.6875rem;
padding: 2px 5px 2px 0; padding: 2px 0 2px 0;
padding-inline-end: 5px;
color: var(--tertiary-foreground); color: var(--tertiary-foreground);
background: var(--primary-background); background: var(--primary-background);
} }
${ props => props.unread && css` ${(props) =>
border-top: thin solid var(--accent); props.unread &&
` } css`
border-top: thin solid var(--accent);
`}
`; `;
const Unread = styled.div` const Unread = styled.div`
...@@ -39,10 +43,8 @@ interface Props { ...@@ -39,10 +43,8 @@ interface Props {
export default function DateDivider(props: Props) { export default function DateDivider(props: Props) {
return ( return (
<Base unread={props.unread}> <Base unread={props.unread}>
{ props.unread && <Unread>NEW</Unread> } {props.unread && <Unread>NEW</Unread>}
<time> <time>{dayjs(props.date).format("LL")}</time>
{ dayjs(props.date).format("LL") }
</time>
</Base> </Base>
); );
} }
import styled, { css } from "styled-components";
export default styled.details<{ sticky?: boolean; large?: boolean }>`
summary {
${(props) =>
props.sticky &&
css`
top: -1px;
z-index: 10;
position: sticky;
`}
${(props) =>
props.large &&
css`
/*padding: 5px 0;*/
background: var(--primary-background);
color: var(--secondary-foreground);
.padding {
/*TOFIX: make this applicable only for the friends list menu, DO NOT REMOVE.*/
display: flex;
align-items: center;
padding: 5px 0;
margin: 0.8em 0px 0.4em;
cursor: pointer;
}
`}
outline: none;
cursor: pointer;
list-style: none;
user-select: none;
align-items: center;
transition: 0.2s opacity;
font-size: 12px;
font-weight: 600;
text-transform: uppercase;
&::marker,
&::-webkit-details-marker {
display: none;
}
.title {
flex-grow: 1;
margin-top: 1px;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
.padding {
display: flex;
align-items: center;
> svg {
flex-shrink: 0;
margin-inline-end: 4px;
transition: 0.2s ease transform;
}
}
}
&:not([open]) {
summary {
opacity: 0.7;
}
summary svg {
transform: rotateZ(-90deg);
}
}
`;
...@@ -3,7 +3,7 @@ import styled, { css } from "styled-components"; ...@@ -3,7 +3,7 @@ import styled, { css } from "styled-components";
interface Props { interface Props {
borders?: boolean; borders?: boolean;
background?: boolean; background?: boolean;
placement: 'primary' | 'secondary' placement: "primary" | "secondary";
} }
export default styled.div<Props>` export default styled.div<Props>`
...@@ -25,6 +25,11 @@ export default styled.div<Props>` ...@@ -25,6 +25,11 @@ export default styled.div<Props>`
flex-shrink: 0; flex-shrink: 0;
} }
.menu {
margin-inline-end: 8px;
color: var(--secondary-foreground);
}
/*@media only screen and (max-width: 768px) { /*@media only screen and (max-width: 768px) {
padding: 0 12px; padding: 0 12px;
}*/ }*/
...@@ -32,20 +37,26 @@ export default styled.div<Props>` ...@@ -32,20 +37,26 @@ export default styled.div<Props>`
@media (pointer: coarse) { @media (pointer: coarse) {
height: 56px; height: 56px;
} }
${ props => props.background && css` ${(props) =>
height: 120px !important; props.background &&
align-items: flex-end; css`
height: 120px !important;
text-shadow: 0px 0px 1px black; align-items: flex-end;
` }
text-shadow: 0px 0px 1px black;
${ props => props.placement === 'secondary' && css` `}
background-color: var(--secondary-header);
padding: 14px; ${(props) =>
` } props.placement === "secondary" &&
css`
${ props => props.borders && css` background-color: var(--secondary-header);
border-end-start-radius: 8px; padding: 14px;
` } `}
${(props) =>
props.borders &&
css`
border-start-start-radius: 8px;
`}
`; `;
import styled, { css } from "styled-components"; import styled, { css } from "styled-components";
interface Props { interface Props {
type?: 'default' | 'circle' rotate?: string;
type?: "default" | "circle";
} }
const normal = `var(--secondary-foreground)`; const normal = `var(--secondary-foreground)`;
...@@ -12,7 +13,7 @@ export default styled.div<Props>` ...@@ -12,7 +13,7 @@ export default styled.div<Props>`
display: grid; display: grid;
cursor: pointer; cursor: pointer;
place-items: center; place-items: center;
transition: .1s ease background-color; transition: 0.1s ease background-color;
fill: ${normal}; fill: ${normal};
color: ${normal}; color: ${normal};
...@@ -22,6 +23,10 @@ export default styled.div<Props>` ...@@ -22,6 +23,10 @@ export default styled.div<Props>`
color: ${normal}; color: ${normal};
} }
svg {
transition: 0.2s ease transform;
}
&:hover { &:hover {
fill: ${hover}; fill: ${hover};
color: ${hover}; color: ${hover};
...@@ -32,13 +37,23 @@ export default styled.div<Props>` ...@@ -32,13 +37,23 @@ export default styled.div<Props>`
} }
} }
${ props => props.type === 'circle' && css` ${(props) =>
padding: 4px; props.type === "circle" &&
border-radius: 50%; css`
background-color: var(--secondary-header); padding: 4px;
border-radius: 50%;
&:hover { background-color: var(--secondary-header);
background-color: var(--primary-header);
} &:hover {
` } background-color: var(--primary-header);
}
`}
${(props) =>
props.rotate &&
css`
svg {
transform: rotateZ(${props.rotate});
}
`}
`; `;
...@@ -6,23 +6,26 @@ interface Props { ...@@ -6,23 +6,26 @@ interface Props {
export default styled.input<Props>` export default styled.input<Props>`
z-index: 1; z-index: 1;
font-size: 1rem;
padding: 8px 16px; padding: 8px 16px;
border-radius: 6px; border-radius: var(--border-radius);
font-family: inherit;
color: var(--foreground); color: var(--foreground);
background: var(--primary-background); background: var(--primary-background);
transition: 0.2s ease background-color; transition: 0.2s ease background-color;
border: none; border: none;
outline: 2px solid transparent; outline: 2px solid transparent;
transition: outline-color 0.2s ease-in-out; transition: outline-color 0.2s ease-in-out;
transition: box-shadow 0.2s ease-in-out;
&:hover { &:hover {
background: var(--secondary-background); background: var(--secondary-background);
} }
&:focus { &:focus {
outline: 2px solid var(--accent); box-shadow: 0 0 0 1.5pt var(--accent);
} }
${(props) => ${(props) =>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
export default function Masks() { export default function Masks() {
return ( return (
<svg width={0} height={0} style={{ position: 'fixed' }}> <svg width={0} height={0} style={{ position: "fixed" }}>
<defs> <defs>
<mask id="server"> <mask id="server">
<rect x="0" y="0" width="32" height="32" fill="white" /> <rect x="0" y="0" width="32" height="32" fill="white" />
...@@ -12,11 +12,15 @@ export default function Masks() { ...@@ -12,11 +12,15 @@ export default function Masks() {
<rect x="0" y="0" width="32" height="32" fill="white" /> <rect x="0" y="0" width="32" height="32" fill="white" />
<circle cx="27" cy="27" r="7" fill={"black"} /> <circle cx="27" cy="27" r="7" fill={"black"} />
</mask> </mask>
<mask id="session">
<rect x="0" y="0" width="32" height="32" fill="white" />
<circle cx="26" cy="28" r="10" fill={"black"} />
</mask>
<mask id="overlap"> <mask id="overlap">
<rect x="0" y="0" width="32" height="32" fill="white" /> <rect x="0" y="0" width="32" height="32" fill="white" />
<circle cx="32" cy="16" r="18" fill={"black"} /> <circle cx="32" cy="16" r="18" fill={"black"} />
</mask> </mask>
</defs> </defs>
</svg> </svg>
) );
} }
\ No newline at end of file