Skip to content

Commit

Permalink
Fix avatars and cohorts
Browse files Browse the repository at this point in the history
  • Loading branch information
moysa committed Dec 4, 2024
1 parent 9ec0c95 commit 1e6269a
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 24 deletions.
34 changes: 23 additions & 11 deletions src/components/Avatar/Avatar.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

@mixin avatar {
position: relative;
background: var(--background-site);
// background: var(--background-site);
border-radius: 50%;
padding: 1px;

Expand Down Expand Up @@ -286,11 +286,11 @@
@include avatar;
width: 42px;
height: 42px;
padding: 3px;
padding: 2px;

.missingBack {
width: 36px;
height: 36px;
width: 38px;
height: 38px;
}

.iconBackground {
Expand All @@ -310,11 +310,11 @@
@include avatar;
width: 44px;
height: 44px;
padding: 3px;
padding: 2px;

.missingBack {
width: 38px;
height: 38px;
width: 40px;
height: 40px;
}

.iconBackground {
Expand Down Expand Up @@ -452,17 +452,23 @@
// height: 74px;
}
}

&.borderRing {
.missingBack {
border: 4px solid var(--background-site);
}
}
}

.xxlAvatar {
@include avatar;
width: 120px;
height: 120px;
padding: 6px;
padding: 5px;

.missingBack {
width: 108px;
height: 108px;
width: 110px;
height: 110px;
}

.iconBackground {
Expand All @@ -473,11 +479,17 @@

&.legend {
.missingBack {
border: 2px solid var(--background-site);
border: 1px solid var(--background-site);
// width: 112px;
// height: 112px;
}
}

&.borderRing {
.missingBack {
border: 4px solid var(--background-site);
}
}
}

.missingBack {
Expand Down
3 changes: 2 additions & 1 deletion src/components/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const Avatar: Component<{
id?: string,
showCheck?: boolean,
zoomable?: boolean,
showBorderRing?: boolean,
legendConfig?: LegendCustomizationConfig,
}> = (props) => {

Expand Down Expand Up @@ -190,7 +191,7 @@ const Avatar: Component<{
return (
<div
id={props.id}
class={`${avatarClass[selectedSize]} ${legendClass()} ${highlightClass()}`}
class={`${avatarClass[selectedSize]} ${legendClass()} ${highlightClass()} ${props.showBorderRing ? styles.borderRing : ''}`}
data-user={props.user?.pubkey}
>
<Show
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

.input {
height: 36px;
width: 100%;
// width: 100%;
flex-grow: 1;
font-size: 16px;
line-height: 20px;
font-weight: 400;
Expand All @@ -34,7 +35,7 @@
border-radius: 18px;
border: none;
color: var(--text-tertiary);
background-color: var(--background-input);
background-color: var(--background-header-input);
display: flex;
align-items: center;
justify-content: flex-start;
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export enum Kind {
ContentStats=10_000_166,
BroadcastStatus=10_000_167,
LegendCustomization=10_000_168,
MembershipCohortInfo = 10_000_169,

WALLET_OPERATION = 10_000_300,
ExchangeRate = 10_000_305,
Expand Down
20 changes: 17 additions & 3 deletions src/contexts/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ export type InvoiceInfo = {
onCancel?: () => void,
};

export type CohortInfo = {
cohort_1: string,
cohort_2: string,
tier: string,
};

export type AppContextStore = {
events: Record<number, NostrEventContent[]>,
isInactive: boolean,
Expand All @@ -80,6 +86,7 @@ export type AppContextStore = {
connectedRelays: Relay[],
verifiedUsers: Record<string, string>,
legendCustomization: Record<string, LegendCustomizationConfig>,
memberCohortInfo: Record<string, CohortInfo>,
actions: {
openReactionModal: (noteId: string, stats: ReactionStats) => void,
closeReactionModal: () => void,
Expand Down Expand Up @@ -131,6 +138,7 @@ const initialData: Omit<AppContextStore, 'actions'> = {
connectedRelays: [],
verifiedUsers: {},
legendCustomization: {},
memberCohortInfo: {},
subscribeToTier: () => {},
};

Expand Down Expand Up @@ -299,7 +307,7 @@ export const AppProvider = (props: { children: JSXElement }) => {

// SOCKET HANDLERS ------------------------------

const handleVerifiedUsersEvent = (content: NostrEventContent) => {
const handleVerifiedUsersEvent = (content: NostrEventContent, subId?: string) => {
if (content.kind === Kind.VerifiedUsersDict) {
const verifiedUsers: Record<string, string> = JSON.parse(content.content);

Expand All @@ -312,6 +320,12 @@ const handleVerifiedUsersEvent = (content: NostrEventContent) => {
updateStore('legendCustomization', (lc) => ({ ...lc, ...config }));
}

if (content.kind === Kind.MembershipCohortInfo) {
const config = JSON.parse(content.content) as Record<string, CohortInfo>;

updateStore('memberCohortInfo', (lc) => ({ ...lc, ...config }));
}

const events = store.events[content.kind] || [];

if (events.length === 0) {
Expand All @@ -335,7 +349,7 @@ const onMessage = async (event: MessageEvent) => {
const data = await readData(event);
const message: NostrEvent | NostrEOSE | NostrEvents = JSON.parse(data);

const [type, _, content] = message;
const [type, subId, content] = message;

if (type === 'EVENTS') {
for (let i=0;i<content.length;i++) {
Expand All @@ -346,7 +360,7 @@ const onMessage = async (event: MessageEvent) => {
}

if (type === 'EVENT') {
handleVerifiedUsersEvent(content)
handleVerifiedUsersEvent(content, subId)
}
};

Expand Down
1 change: 0 additions & 1 deletion src/pages/Premium/Premium.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,6 @@
}

.premiumActive {
margin-bottom: 32px;
.expiredPremium, .activePremium, .legendPremium {
display: flex;
justify-content: center;
Expand Down
35 changes: 35 additions & 0 deletions src/pages/Premium/PremiumCohortInfo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Component, Match, Switch } from 'solid-js';

import styles from './Premium.module.scss';
import { useIntl } from '@cookbook/solid-intl';
import { useNavigate } from '@solidjs/router';
import { PremiumStore } from './Premium';
import Avatar from '../../components/Avatar/Avatar';
import VerificationCheck from '../../components/VerificationCheck/VerificationCheck';
import { shortDate } from '../../lib/dates';
import { userName } from '../../stores/profile';
import { PrimalUser } from '../../types/primal';
import { LegendCustomizationConfig } from '../../lib/premium';
import { CohortInfo } from '../../contexts/AppContext';


const PremiumCohortInfo: Component<{
cohortInfo: CohortInfo,
legendConfig?: LegendCustomizationConfig | undefined,
}> = (props) => {
const intl = useIntl()
const navigate = useNavigate();

return (
<div class={styles.premiumActive}>
<div class={`${styles.legendPremium} ${styles[`legend_${props.legendConfig?.style}`]}`}>
<div class={styles.caption}>{props.cohortInfo.cohort_1 || ''}</div>
<div class={styles.date}>
<div>{props.cohortInfo.cohort_2}</div>
</div>
</div>
</div>
);
}

export default PremiumCohortInfo;
9 changes: 5 additions & 4 deletions src/pages/Profile.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
z-index: var(--z-index-floater);
.avatar {
// border: solid 4px var(--background-site);
border-radius: 50%;
background-color: var(--background-site);
// border-radius: 50%;
// background-color: var(--background-site);
// >div {
// opacity: 0;
// animation: fadeIn var(--profile-animation-duration) ease-in forwards;
Expand Down Expand Up @@ -352,6 +352,7 @@
display: flex;
align-items: center;
justify-content: flex-start;
gap: 4px;

.text {
color: var(--text-primary);
Expand All @@ -371,8 +372,8 @@
}

.vc {
width: 20px;
height: 20px;
// width: 20px;
// height: 20px;
}
}

Expand Down
27 changes: 25 additions & 2 deletions src/pages/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import ProfileFollowModal from '../components/ProfileFollowModal/ProfileFollowMo
import ProfileCardSkeleton from '../components/Skeleton/ProfileCardSkeleton';
import { getKnownProfiles } from '../Router';
import { scrollWindowTo } from '../lib/scroll';
import PremiumCohortInfo from './Premium/PremiumCohortInfo';

const Profile: Component = () => {

Expand Down Expand Up @@ -650,6 +651,14 @@ const Profile: Component = () => {
return text.length < 50;
}

const isVisibleLegend = () => {
return profile?.profileKey &&
app?.legendCustomization[profile.profileKey] &&
app?.memberCohortInfo[profile.profileKey] &&
app?.legendCustomization[profile.profileKey].style !== '' &&
app?.memberCohortInfo[profile.profileKey].tier === 'premium-legend';
}

return (
<>
<PageTitle title={
Expand Down Expand Up @@ -717,14 +726,20 @@ const Profile: Component = () => {
width={640}
media={media?.actions.getMedia(banner() || '', 'o')}
mediaThumb={media?.actions.getMedia(banner() || '', 'm') || media?.actions.getMedia(banner() || '', 'o') || banner()}
ignoreRatio={true}
/>
</Show>
</div>

<div class={`${styles.userImage} animated`}>
<div class={styles.avatar}>
<div class={`styles.avatar`}>
<div class={isSmallScreen() ? styles.phoneAvatar : styles.desktopAvatar}>
<Avatar user={profile?.userProfile} size={isSmallScreen() ? "lg" : "xxl"} zoomable={true} />
<Avatar
user={profile?.userProfile}
size={isSmallScreen() ? "lg" : "xxl"}
zoomable={true}
showBorderRing={!isVisibleLegend()}
/>
</div>
</div>
</div>
Expand Down Expand Up @@ -813,6 +828,14 @@ const Profile: Component = () => {
<VerificationCheck user={profile?.userProfile} large={true} />
</div>
</Show>

<Show when={isVisibleLegend()}>
<PremiumCohortInfo
cohortInfo={app?.memberCohortInfo[profile?.profileKey]}
legendConfig={app?.legendCustomization[profile?.profileKey]}
/>
</Show>

<Show when={isFollowingYou()}>
<div class={styles.followsBadge}>
{intl.formatMessage(t.followsYou)}
Expand Down
8 changes: 8 additions & 0 deletions src/types/primal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,13 @@ export type NostrBroadcastStatus= {
id?: string,
};

export type NostrMembershipCohortInfo= {
kind: Kind.MembershipCohortInfo,
content: string,
created_at?: number,
id?: string,
};

export type NostrEventContent =
NostrNoteContent |
NostrUserContent |
Expand Down Expand Up @@ -453,6 +460,7 @@ export type NostrEventContent =
NostrOrderHistory |
NostrLegendCustomization |
NostrBroadcastStatus |
NostrMembershipCohortInfo |
NostrTopicStats;

export type NostrEvent = [
Expand Down

0 comments on commit 1e6269a

Please sign in to comment.