From f9c30a99cfdb6a25310a78f8ca3298d3680f1d32 Mon Sep 17 00:00:00 2001 From: Ilya Y <75578537+ilya-bkv@users.noreply.github.com> Date: Fri, 11 Aug 2023 19:42:41 +0300 Subject: [PATCH] Update Userpic component (#160) --- src/components/Article/Comment.tsx | 5 +- src/components/Author/AuthorCard.tsx | 5 +- src/components/Author/Userpic.tsx | 65 ------------------- .../Author/{ => Userpic}/Userpic.module.scss | 42 ++++++------ src/components/Author/Userpic/Userpic.tsx | 62 ++++++++++++++++++ src/components/Author/Userpic/index.ts | 1 + src/components/Feed/Sidebar/Sidebar.tsx | 7 +- src/components/Nav/HeaderAuth.tsx | 8 ++- src/components/Views/Author/Author.tsx | 6 +- .../ConditionalWrapper/ConditionalWrapper.tsx | 11 ++++ .../_shared/ConditionalWrapper/index.ts | 1 + .../_shared/VotersList/VotersList.tsx | 13 ++-- src/pages/profile/Settings.module.scss | 28 -------- src/pages/profile/profileSettings.page.tsx | 22 +++---- 14 files changed, 137 insertions(+), 139 deletions(-) delete mode 100644 src/components/Author/Userpic.tsx rename src/components/Author/{ => Userpic}/Userpic.module.scss (75%) create mode 100644 src/components/Author/Userpic/Userpic.tsx create mode 100644 src/components/Author/Userpic/index.ts create mode 100644 src/components/_shared/ConditionalWrapper/ConditionalWrapper.tsx create mode 100644 src/components/_shared/ConditionalWrapper/index.ts diff --git a/src/components/Article/Comment.tsx b/src/components/Article/Comment.tsx index 114a54f4..c8cc6028 100644 --- a/src/components/Article/Comment.tsx +++ b/src/components/Article/Comment.tsx @@ -4,7 +4,7 @@ import { getPagePath } from '@nanostores/router' import MD from './MD' import { AuthorCard } from '../Author/AuthorCard' -import Userpic from '../Author/Userpic' +import { Userpic } from '../Author/Userpic' import { CommentRatingControl } from './CommentRatingControl' import { CommentDate } from './CommentDate' import { ShowIfAuthenticated } from '../_shared/ShowIfAuthenticated' @@ -123,7 +123,8 @@ export const Comment = (props: Props) => { fallback={
{ }} > { - const letters = () => { - const names = props.user && props.user.name ? props.user.name.split(' ') : [] - - return names[0][0] + (names.length > 1 ? names[1][0] : '') - } - - return ( -
- - - - } - > -
{letters()}
-
-
-
- - - - } - > -
{letters()}
-
-
-
- ) -} diff --git a/src/components/Author/Userpic.module.scss b/src/components/Author/Userpic/Userpic.module.scss similarity index 75% rename from src/components/Author/Userpic.module.scss rename to src/components/Author/Userpic/Userpic.module.scss index 7981d9bf..1dc106ac 100644 --- a/src/components/Author/Userpic.module.scss +++ b/src/components/Author/Userpic/Userpic.module.scss @@ -1,4 +1,4 @@ -.circlewrap { +.Userpic { align-items: baseline; background: #f7f7f8; border-radius: 100%; @@ -19,7 +19,7 @@ display: block; } - .userpic { + .letters { background-color: white; border-radius: 50%; border: 1.5px solid black; @@ -53,24 +53,24 @@ color: #000; } } -} -.big.circlewrap { - margin-right: 0; - max-width: 168px; - min-width: 168px; - height: 168px; - width: 168px; + &.big { + margin-right: 0; + max-width: 168px; + min-width: 168px; + height: 168px; + width: 168px; - @include media-breakpoint-up(md) { - margin-right: 4.8rem; - } + @include media-breakpoint-up(md) { + margin-right: 4.8rem; + } - .userpic { - font-size: 2em; - line-height: 168px; - max-width: 100%; - width: 100%; + .letters { + font-size: 2em; + line-height: 168px; + max-width: 100%; + width: 100%; + } } } @@ -81,16 +81,20 @@ height: 6.8rem; width: 6.8rem; - .userpic { + .letters { line-height: 6.4rem; } } .feedMode { - .userpic { + .letters { font-size: 0.8rem; line-height: 14px; min-width: 16px; max-width: 16px; } } + +.cursorPointer { + cursor: pointer; +} diff --git a/src/components/Author/Userpic/Userpic.tsx b/src/components/Author/Userpic/Userpic.tsx new file mode 100644 index 00000000..57c205bd --- /dev/null +++ b/src/components/Author/Userpic/Userpic.tsx @@ -0,0 +1,62 @@ +import { Show } from 'solid-js' +import type { Author, User } from '../../../graphql/types.gen' +import styles from './Userpic.module.scss' +import { clsx } from 'clsx' +import { imageProxy } from '../../../utils/imageProxy' +import { ConditionalWrapper } from '../../_shared/ConditionalWrapper' +import { Loading } from '../../_shared/Loading' + +type Props = { + name: string + userpic: string + class?: string + slug?: string + onClick?: () => void + loading?: boolean + isBig?: boolean + hasLink?: boolean + + isAuthorsList?: boolean + isFeedMode?: boolean +} + +export const Userpic = (props: Props) => { + const letters = () => { + if (!props.name) return + const names = props.name ? props.name.split(' ') : [] + return names[0][0] + (names.length > 1 ? names[1][0] : '') + } + + return ( +
+ }> + {children}} + > + + } + > +
{letters()}
+
+
+
+
+ ) +} diff --git a/src/components/Author/Userpic/index.ts b/src/components/Author/Userpic/index.ts new file mode 100644 index 00000000..041a2955 --- /dev/null +++ b/src/components/Author/Userpic/index.ts @@ -0,0 +1 @@ +export { Userpic } from './Userpic' diff --git a/src/components/Feed/Sidebar/Sidebar.tsx b/src/components/Feed/Sidebar/Sidebar.tsx index e93fc5bf..a886ec62 100644 --- a/src/components/Feed/Sidebar/Sidebar.tsx +++ b/src/components/Feed/Sidebar/Sidebar.tsx @@ -9,7 +9,7 @@ import { useSession } from '../../../context/session' import { useLocalize } from '../../../context/localize' import styles from './Sidebar.module.scss' import { clsx } from 'clsx' -import Userpic from '../../Author/Userpic' +import { Userpic } from '../../Author/Userpic' import { getPagePath } from '@nanostores/router' import { router, useRouter } from '../../../stores/router' @@ -138,7 +138,10 @@ export const Sidebar = (props: FeedSidebarProps) => { >
- + diff --git a/src/components/Nav/HeaderAuth.tsx b/src/components/Nav/HeaderAuth.tsx index 8359063c..6eaae6a8 100644 --- a/src/components/Nav/HeaderAuth.tsx +++ b/src/components/Nav/HeaderAuth.tsx @@ -5,7 +5,7 @@ import { Icon } from '../_shared/Icon' import { createMemo, createSignal, onCleanup, onMount, Show } from 'solid-js' import Notifications from './Notifications' import { ProfilePopup } from './ProfilePopup' -import Userpic from '../Author/Userpic' +import { Userpic } from '../Author/Userpic' import { showModal, useWarningsStore } from '../../stores/ui' import { ShowOnlyOnClient } from '../_shared/ShowOnlyOnClient' import { useSession } from '../../context/session' @@ -216,7 +216,11 @@ export const HeaderAuth = (props: Props) => {
diff --git a/src/components/Views/Author/Author.tsx b/src/components/Views/Author/Author.tsx index 82f2b8e8..171e2e2c 100644 --- a/src/components/Views/Author/Author.tsx +++ b/src/components/Views/Author/Author.tsx @@ -12,7 +12,7 @@ import { splitToPages } from '../../../utils/splitToPages' import styles from './Author.module.scss' import stylesArticle from '../../Article/Article.module.scss' import { clsx } from 'clsx' -import Userpic from '../../Author/Userpic' +import { Userpic } from '../../Author/Userpic' import { Popup } from '../../_shared/Popup' import { AuthorCard } from '../../Author/AuthorCard' import { apiClient } from '../../../utils/apiClient' @@ -178,12 +178,12 @@ export const AuthorView = (props: AuthorProps) => { - {(f) => } + {(f) => } 3}> - {(f) => } + {(f) => }
{followers().length} diff --git a/src/components/_shared/ConditionalWrapper/ConditionalWrapper.tsx b/src/components/_shared/ConditionalWrapper/ConditionalWrapper.tsx new file mode 100644 index 00000000..3fea36ba --- /dev/null +++ b/src/components/_shared/ConditionalWrapper/ConditionalWrapper.tsx @@ -0,0 +1,11 @@ +import { JSX } from 'solid-js' + +type Props = { + condition: boolean + wrapper: (children: JSX.Element) => JSX.Element + children: JSX.Element +} + +export const ConditionalWrapper = (props: Props) => { + return props.condition ? props.wrapper(props.children) : props.children +} diff --git a/src/components/_shared/ConditionalWrapper/index.ts b/src/components/_shared/ConditionalWrapper/index.ts new file mode 100644 index 00000000..856578ce --- /dev/null +++ b/src/components/_shared/ConditionalWrapper/index.ts @@ -0,0 +1 @@ +export { ConditionalWrapper } from './ConditionalWrapper' diff --git a/src/components/_shared/VotersList/VotersList.tsx b/src/components/_shared/VotersList/VotersList.tsx index 60e69705..53bed086 100644 --- a/src/components/_shared/VotersList/VotersList.tsx +++ b/src/components/_shared/VotersList/VotersList.tsx @@ -1,7 +1,7 @@ -import type { Reaction } from '../../../graphql/types.gen' -import { Author, ReactionKind } from '../../../graphql/types.gen' import { For, Show } from 'solid-js' -import Userpic from '../../Author/Userpic' +import type { Reaction } from '../../../graphql/types.gen' +import { ReactionKind } from '../../../graphql/types.gen' +import { Userpic } from '../../Author/Userpic' import styles from './VotersList.module.scss' import { clsx } from 'clsx' @@ -22,7 +22,12 @@ export const VotersList = (props: Props) => { {(reaction) => (
  • {reaction.kind === ReactionKind.Like ? ( diff --git a/src/pages/profile/Settings.module.scss b/src/pages/profile/Settings.module.scss index f180b7f2..5282c107 100644 --- a/src/pages/profile/Settings.module.scss +++ b/src/pages/profile/Settings.module.scss @@ -13,34 +13,6 @@ h5 { margin: 0 0 0.8rem; } -.avatarContainer { - border-radius: 100%; - overflow: hidden; - position: relative; - height: 18rem; - width: 18rem; -} - -.avatar { - height: 100%; - left: 0; - position: absolute; - top: 0; - width: 100%; - cursor: pointer; - background: #ccc; - border: none; - object-fit: cover; - object-position: center; -} - -.avatarInput { - border-radius: 100%; - cursor: pointer; - opacity: 0; - z-index: 1; -} - .multipleControls { margin-top: 3rem; } diff --git a/src/pages/profile/profileSettings.page.tsx b/src/pages/profile/profileSettings.page.tsx index f636f774..2a8ebf68 100644 --- a/src/pages/profile/profileSettings.page.tsx +++ b/src/pages/profile/profileSettings.page.tsx @@ -7,13 +7,12 @@ import styles from './Settings.module.scss' import { useProfileForm } from '../../context/profile' import { validateUrl } from '../../utils/validateUrl' import { createFileUploader } from '@solid-primitives/upload' -import { Loading } from '../../components/_shared/Loading' import { useSession } from '../../context/session' import { Button } from '../../components/_shared/Button' import { useSnackbar } from '../../context/snackbar' import { useLocalize } from '../../context/localize' -import { Image } from '../../components/_shared/Image' import { handleFileUpload } from '../../utils/handleFileUpload' +import { Userpic } from '../../components/Author/Userpic' export const ProfileSettingsPage = () => { const { t } = useLocalize() @@ -72,6 +71,8 @@ export const ProfileSettingsPage = () => { const [hostname, setHostname] = createSignal(null) onMount(() => setHostname(window?.location.host)) + + console.log('!!! form:', form) return ( @@ -90,16 +91,13 @@ export const ProfileSettingsPage = () => {

    {t('Userpic')}

    -
    - }> - {form.name} - -
    +

    {t('Name')}