From a64fe611997ed42ced9a884073aead39f5808c54 Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Sun, 29 May 2022 16:40:02 +0100 Subject: [PATCH] feat(@ui): migrate date divider and details --- src/components/common/CollapsibleSection.tsx | 4 +- src/components/ui/DateDivider.tsx | 53 ------------ src/components/ui/Details.tsx | 82 ------------------- .../channels/messaging/MessageRenderer.tsx | 7 +- 4 files changed, 6 insertions(+), 140 deletions(-) delete mode 100644 src/components/ui/DateDivider.tsx delete mode 100644 src/components/ui/Details.tsx diff --git a/src/components/common/CollapsibleSection.tsx b/src/components/common/CollapsibleSection.tsx index cea03b06..21b9c12c 100644 --- a/src/components/common/CollapsibleSection.tsx +++ b/src/components/common/CollapsibleSection.tsx @@ -1,8 +1,8 @@ import { ChevronDown } from "@styled-icons/boxicons-regular"; -import { useApplicationState } from "../../mobx/State"; +import { Details } from "@revoltchat/ui"; -import Details from "../ui/Details"; +import { useApplicationState } from "../../mobx/State"; import { Children } from "../../types/Preact"; diff --git a/src/components/ui/DateDivider.tsx b/src/components/ui/DateDivider.tsx deleted file mode 100644 index f50af712..00000000 --- a/src/components/ui/DateDivider.tsx +++ /dev/null @@ -1,53 +0,0 @@ -import styled, { css } from "styled-components/macro"; - -import { dayjs } from "../../context/Locale"; - -const Base = styled.div<{ unread?: boolean }>` - height: 0; - display: flex; - user-select: none; - align-items: center; - margin: 17px 12px 5px; - border-top: thin solid var(--tertiary-foreground); - - time { - margin-top: -2px; - font-size: 0.6875rem; - line-height: 0.6875rem; - padding-inline-start: 5px; - padding-inline-end: 5px; - color: var(--tertiary-foreground); - background: var(--primary-background); - } - - ${(props) => - props.unread && - css` - border-top: thin solid var(--accent); - `} -`; - -const Unread = styled.div` - background: var(--accent); - color: var(--accent-contrast); - font-size: 7px; - padding: 2px 6px; - font-size: 10px; - border-radius: 60px; - font-weight: 600; - margin-top: -1px; -`; - -interface Props { - date?: Date; - unread?: boolean; -} - -export default function DateDivider({ unread, date }: Props) { - return ( - - {unread && NEW} - {date && } - - ); -} diff --git a/src/components/ui/Details.tsx b/src/components/ui/Details.tsx deleted file mode 100644 index 7e905366..00000000 --- a/src/components/ui/Details.tsx +++ /dev/null @@ -1,82 +0,0 @@ -import styled, { css } from "styled-components/macro"; - -import { isTouchscreenDevice } from "../../lib/isTouchscreenDevice"; - -export default styled.details<{ sticky?: boolean; large?: boolean }>` - summary { - ${(props) => - props.sticky && - css` - top: 48px; - z-index: 10; - position: sticky; - ${() => - isTouchscreenDevice && - css` - top: 56px; - `} - `} - - ${(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); - } - } -`; diff --git a/src/pages/channels/messaging/MessageRenderer.tsx b/src/pages/channels/messaging/MessageRenderer.tsx index 939cee23..1813190a 100644 --- a/src/pages/channels/messaging/MessageRenderer.tsx +++ b/src/pages/channels/messaging/MessageRenderer.tsx @@ -11,6 +11,8 @@ import { decodeTime } from "ulid"; import { Text } from "preact-i18n"; import { useEffect, useState } from "preact/hooks"; +import { MessageDivider } from "@revoltchat/ui"; + import { internalSubscribe, internalEmit } from "../../../lib/eventEmitter"; import { ChannelRenderer } from "../../../lib/renderer/Singleton"; @@ -21,12 +23,11 @@ import { useClient } from "../../../context/revoltjs/RevoltClient"; import Message from "../../../components/common/messaging/Message"; import { SystemMessage } from "../../../components/common/messaging/SystemMessage"; -import DateDivider from "../../../components/ui/DateDivider"; import Preloader from "../../../components/ui/Preloader"; - import { Children } from "../../../types/Preact"; import ConversationStart from "./ConversationStart"; import MessageEditor from "./MessageEditor"; +import dayjs from "dayjs"; interface Props { last_id?: string; @@ -125,7 +126,7 @@ export default observer(({ last_id, renderer, highlight }: Props) => { } if (unread || date) { - render.push(); + render.push(); head = true; }