mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
Change bookmarks and migration (#675)
* changed bookmark structure to list of dids * fixed add, remove bookmark * wip * fixed type error and migration * remove logs * fix lint error Co-authored-by: Norbi <katunanorbert@gmai.com>
This commit is contained in:
parent
f9f3768f5f
commit
064bb2fd69
@ -85,15 +85,13 @@ export default function Bookmarks(): ReactElement {
|
|||||||
const [pinned, setPinned] = useState<DDO[]>()
|
const [pinned, setPinned] = useState<DDO[]>()
|
||||||
const [isLoading, setIsLoading] = useState<boolean>()
|
const [isLoading, setIsLoading] = useState<boolean>()
|
||||||
|
|
||||||
const networkName = (config as ConfigHelperConfig)?.network
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!appConfig.metadataCacheUri || !networkName || bookmarks === {}) return
|
if (!appConfig.metadataCacheUri || bookmarks === []) return
|
||||||
|
|
||||||
const source = axios.CancelToken.source()
|
const source = axios.CancelToken.source()
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
if (!bookmarks[networkName]?.length) {
|
if (!bookmarks?.length) {
|
||||||
setPinned([])
|
setPinned([])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -102,7 +100,7 @@ export default function Bookmarks(): ReactElement {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const resultPinned = await getAssetsBookmarked(
|
const resultPinned = await getAssetsBookmarked(
|
||||||
bookmarks[networkName],
|
bookmarks,
|
||||||
appConfig.metadataCacheUri,
|
appConfig.metadataCacheUri,
|
||||||
source.token
|
source.token
|
||||||
)
|
)
|
||||||
@ -118,7 +116,7 @@ export default function Bookmarks(): ReactElement {
|
|||||||
return () => {
|
return () => {
|
||||||
source.cancel()
|
source.cancel()
|
||||||
}
|
}
|
||||||
}, [bookmarks, appConfig.metadataCacheUri, networkName])
|
}, [bookmarks, appConfig.metadataCacheUri])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Table
|
<Table
|
||||||
|
@ -2,15 +2,12 @@ import { useUserPreferences } from '../../../providers/UserPreferences'
|
|||||||
import React, { ReactElement } from 'react'
|
import React, { ReactElement } from 'react'
|
||||||
import styles from './Bookmark.module.css'
|
import styles from './Bookmark.module.css'
|
||||||
import { ReactComponent as BookmarkIcon } from '../../../images/bookmark.svg'
|
import { ReactComponent as BookmarkIcon } from '../../../images/bookmark.svg'
|
||||||
import { ConfigHelperConfig } from '@oceanprotocol/lib'
|
|
||||||
import { useOcean } from '../../../providers/Ocean'
|
import { useOcean } from '../../../providers/Ocean'
|
||||||
|
|
||||||
export default function Bookmark({ did }: { did: string }): ReactElement {
|
export default function Bookmark({ did }: { did: string }): ReactElement {
|
||||||
const { config } = useOcean()
|
const { config } = useOcean()
|
||||||
const { bookmarks, addBookmark, removeBookmark } = useUserPreferences()
|
const { bookmarks, addBookmark, removeBookmark } = useUserPreferences()
|
||||||
const isBookmarked =
|
const isBookmarked = bookmarks && bookmarks?.includes(did)
|
||||||
bookmarks &&
|
|
||||||
bookmarks[(config as ConfigHelperConfig).network]?.includes(did)
|
|
||||||
|
|
||||||
function handleBookmark() {
|
function handleBookmark() {
|
||||||
isBookmarked ? removeBookmark(did) : addBookmark(did)
|
isBookmarked ? removeBookmark(did) : addBookmark(did)
|
||||||
|
@ -80,7 +80,7 @@ export default function AssetContent(props: AssetContentProps): ReactElement {
|
|||||||
{showPricing && <Pricing ddo={ddo} />}
|
{showPricing && <Pricing ddo={ddo} />}
|
||||||
<div className={styles.content}>
|
<div className={styles.content}>
|
||||||
<MetaMain />
|
<MetaMain />
|
||||||
{/* <Bookmark did={ddo.id} /> */}
|
<Bookmark did={ddo.id} />
|
||||||
|
|
||||||
{isInPurgatory ? (
|
{isInPurgatory ? (
|
||||||
<Alert
|
<Alert
|
||||||
|
@ -141,7 +141,7 @@ export default function HomePage(): ReactElement {
|
|||||||
|
|
||||||
<section className={styles.section}>
|
<section className={styles.section}>
|
||||||
<h3>Bookmarks</h3>
|
<h3>Bookmarks</h3>
|
||||||
{/* <Bookmarks /> */}
|
<Bookmarks />
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
{queryAndDids && (
|
{queryAndDids && (
|
||||||
|
@ -15,9 +15,7 @@ interface UserPreferencesValue {
|
|||||||
currency: string
|
currency: string
|
||||||
locale: string
|
locale: string
|
||||||
chainIds: number[]
|
chainIds: number[]
|
||||||
bookmarks: {
|
bookmarks: string[]
|
||||||
[network: string]: string[]
|
|
||||||
}
|
|
||||||
setChainIds: (chainIds: number[]) => void
|
setChainIds: (chainIds: number[]) => void
|
||||||
setDebug: (value: boolean) => void
|
setDebug: (value: boolean) => void
|
||||||
setCurrency: (value: string) => void
|
setCurrency: (value: string) => void
|
||||||
@ -56,7 +54,7 @@ function UserPreferencesProvider({
|
|||||||
localStorage?.currency || 'EUR'
|
localStorage?.currency || 'EUR'
|
||||||
)
|
)
|
||||||
const [locale, setLocale] = useState<string>()
|
const [locale, setLocale] = useState<string>()
|
||||||
const [bookmarks, setBookmarks] = useState(localStorage?.bookmarks || {})
|
const [bookmarks, setBookmarks] = useState(localStorage?.bookmarks || [])
|
||||||
const [chainIds, setChainIds] = useState(
|
const [chainIds, setChainIds] = useState(
|
||||||
localStorage?.chainIds || appConfig.chainIds
|
localStorage?.chainIds || appConfig.chainIds
|
||||||
)
|
)
|
||||||
@ -79,28 +77,25 @@ function UserPreferencesProvider({
|
|||||||
setLocale(window.navigator.language)
|
setLocale(window.navigator.language)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// function addBookmark(didToAdd: string): void {
|
function addBookmark(didToAdd: string): void {
|
||||||
// const newPinned = {
|
const newPinned = [...bookmarks, didToAdd]
|
||||||
// ...bookmarks,
|
setBookmarks(newPinned)
|
||||||
// [networkName]: [didToAdd].concat(bookmarks[networkName])
|
}
|
||||||
// }
|
|
||||||
// setBookmarks(newPinned)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// function removeBookmark(didToAdd: string): void {
|
function removeBookmark(didToAdd: string): void {
|
||||||
// const newPinned = {
|
const newPinned = bookmarks.filter((did: string) => did !== didToAdd)
|
||||||
// ...bookmarks,
|
setBookmarks(newPinned)
|
||||||
// [networkName]: bookmarks[networkName].filter(
|
}
|
||||||
// (did: string) => did !== didToAdd
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
// setBookmarks(newPinned)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Bookmarks old data structure migration
|
// Bookmarks old data structure migration
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!bookmarks.length) return
|
if (bookmarks.length !== undefined) return
|
||||||
const newPinned = { mainnet: bookmarks as any }
|
const newPinned: string[] = []
|
||||||
|
for (const network in bookmarks) {
|
||||||
|
;(bookmarks[network] as unknown as string[]).forEach((did: string) => {
|
||||||
|
did !== null && newPinned.push(did)
|
||||||
|
})
|
||||||
|
}
|
||||||
setBookmarks(newPinned)
|
setBookmarks(newPinned)
|
||||||
}, [bookmarks])
|
}, [bookmarks])
|
||||||
|
|
||||||
@ -115,9 +110,9 @@ function UserPreferencesProvider({
|
|||||||
bookmarks,
|
bookmarks,
|
||||||
setChainIds,
|
setChainIds,
|
||||||
setDebug,
|
setDebug,
|
||||||
setCurrency
|
setCurrency,
|
||||||
// addBookmark,
|
addBookmark,
|
||||||
// removeBookmark
|
removeBookmark
|
||||||
} as UserPreferencesValue
|
} as UserPreferencesValue
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user