Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
araujobarret committed Aug 8, 2023
1 parent ad94ac3 commit 1c948bb
Show file tree
Hide file tree
Showing 5 changed files with 1,023 additions and 909 deletions.
9 changes: 9 additions & 0 deletions src/app/Components/ArtworkGrids/ArtworkGridItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { DurationProvider } from "app/Components/Countdown"
import OpaqueImageView from "app/Components/OpaqueImageView/OpaqueImageView"

import { OpaqueImageView as NewOpaqueImageView } from "app/Components/OpaqueImageView2"
import { ProgressiveOnboardingSaveArtwork } from "app/Components/ProgressiveOnboarding/ProgressiveOnboardingSaveArtwork"
import { GlobalStore } from "app/store/GlobalStore"
import { PageableRouteProps } from "app/system/navigation/useNavigateToPageableRoute"
import { useArtworkBidding } from "app/utils/Websockets/auctions/useArtworkBidding"
Expand Down Expand Up @@ -350,6 +351,14 @@ export const Artwork: React.FC<ArtworkProps> = ({
width={SAVE_ICON_SIZE}
fill="blue100"
/>
) : itemIndex === 0 ? (
<ProgressiveOnboardingSaveArtwork>
<HeartIcon
testID="empty-heart-icon"
height={SAVE_ICON_SIZE}
width={SAVE_ICON_SIZE}
/>
</ProgressiveOnboardingSaveArtwork>
) : (
<HeartIcon
testID="empty-heart-icon"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Flex, Popover, Text } from "@artsy/palette-mobile"
// import { GlobalStore } from "app/store/GlobalStore"
// import { PROGRESSIVE_ONBOARDING_SAVE_ARTWORK } from "app/store/ProgressiveOnboardingModel"
import { useState } from "react"

export const ProgressiveOnboardingSaveArtwork: React.FC = ({ children }) => {
const [visible, setVisible] = useState(true)
// const { dismiss } = GlobalStore.actions.progressiveOnboarding
// const { isDismissed } = GlobalStore.useAppState((state) => state.progressiveOnboarding)

// const visible = isDismissed(PROGRESSIVE_ONBOARDING_SAVE_ARTWORK).status

if (!visible) {
;<>{children}</>
}

return (
<Popover
visible={visible}
// onDismiss={() => dismiss({ key: "save-artwork" })}
onDismiss={() => setVisible(false)}
onPressOutside={() => setVisible(false)}
title={
<Text weight="medium" color="white100">
Like what you see?
</Text>
}
content={<Text color="white100">Hit the heart to save an artwork.</Text>}
>
<Flex>{children}</Flex>
</Popover>
)
}
6 changes: 6 additions & 0 deletions src/app/store/GlobalStoreModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import {
SubmissionModel,
} from "app/Scenes/SellWithArtsy/utils/submissionModelState"
import { unsafe__getEnvironment } from "app/store/GlobalStore"
import {
ProgressiveOnboardingModel,
getProgressiveOnboardingModel,
} from "app/store/ProgressiveOnboardingModel"
import { Action, action, createStore, State, thunkOn, ThunkOn } from "easy-peasy"
import { ArtsyPrefsModel, getArtsyPrefsModel } from "./ArtsyPrefsModel"
import { AuthModel, getAuthModel } from "./AuthModel"
Expand Down Expand Up @@ -52,6 +56,7 @@ interface GlobalStoreStateModel {
artworkSubmission: SubmissionModel
requestedPriceEstimates: RequestedPriceEstimatesModel
recentPriceRanges: RecentPriceRangesModel
progressiveOnboarding: ProgressiveOnboardingModel
}
export interface GlobalStoreModel extends GlobalStoreStateModel {
rehydrate: Action<this, DeepPartial<State<GlobalStoreStateModel>>>
Expand Down Expand Up @@ -139,6 +144,7 @@ export const getGlobalStoreModel = (): GlobalStoreModel => ({
artworkSubmission: getSubmissionModel(),
requestedPriceEstimates: getRequestedPriceEstimatesModel(),
recentPriceRanges: getRecentPriceRangesModel(),
progressiveOnboarding: getProgressiveOnboardingModel(),

setSessionState: action((state, payload) => {
state.sessionState = { ...state.sessionState, ...payload }
Expand Down
62 changes: 62 additions & 0 deletions src/app/store/ProgressiveOnboardingModel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { GlobalStore } from "app/store/GlobalStore"
import { Action, Computed, action, computed } from "easy-peasy"
import { uniqBy } from "lodash"

interface DismissedKey {
key: ProgressiveOnboardingKey
timestamp: number
}

interface DismissedKeyStatus {
status: boolean
timestamp: number
}

export interface ProgressiveOnboardingModel {
dismissed: Record<string, DismissedKey[]>
dismiss: Action<this, { key: ProgressiveOnboardingKey | readonly ProgressiveOnboardingKey[] }>
isDismissed: Computed<this, (key: ProgressiveOnboardingKey) => DismissedKeyStatus>
}

export const getProgressiveOnboardingModel = (): ProgressiveOnboardingModel => ({
dismissed: {},
dismiss: action((state, { key }) => {
const userId = GlobalStore.useAppState((state) => state.auth.userID)
if (!userId) {
return
}

const keys = Array.isArray(key) ? key : [key]
const timestamp = Date.now()

state.dismissed = {
...state.dismissed,
[userId]: uniqBy(
[...state.dismissed[userId], ...keys.map((k) => ({ key: k, timestamp }))],
(d) => d.key
),
}
}),
isDismissed: computed(({ dismissed }) => {
return (key) => {
const userId = GlobalStore.useAppState((state) => state.auth.userID)
if (!userId || !dismissed[userId]) {
return { status: false, timestamp: 0 }
}

const dismissedKey = dismissed[userId].find((d) => d.key === key)

return dismissedKey
? { status: true, timestamp: dismissedKey.timestamp }
: { status: false, timestamp: 0 }
}
}),
})

// Saves
export const PROGRESSIVE_ONBOARDING_SAVE_ARTWORK = "save-artwork"
export const PROGRESSIVE_ONBOARDING_SAVE_CHAIN = [PROGRESSIVE_ONBOARDING_SAVE_ARTWORK]

export const PROGRESSIVE_ONBOARDING_KEYS = [PROGRESSIVE_ONBOARDING_SAVE_ARTWORK] as const

export type ProgressiveOnboardingKey = typeof PROGRESSIVE_ONBOARDING_KEYS[number]
Loading

0 comments on commit 1c948bb

Please sign in to comment.