From e0bad7df707f9ef79cfde2d362779d8682640fb0 Mon Sep 17 00:00:00 2001
From: Ren Amamiya <123083837+reyamir@users.noreply.github.com>
Date: Wed, 19 Apr 2023 17:35:54 +0700
Subject: [PATCH] temp remove browse channels page and add default channel list
---
src/components/channels/channelList.tsx | 10 ++++++----
src/components/channels/channelListItem.tsx | 6 ++++--
src/stores/constants.tsx | 20 ++++++++++++++++++++
src/utils/hooks/useChannelMetadata.tsx | 8 ++++++--
4 files changed, 36 insertions(+), 8 deletions(-)
diff --git a/src/components/channels/channelList.tsx b/src/components/channels/channelList.tsx
index 3d5b08d9..e6ecb109 100644
--- a/src/components/channels/channelList.tsx
+++ b/src/components/channels/channelList.tsx
@@ -1,15 +1,16 @@
import { ChannelListItem } from '@components/channels/channelListItem';
import { CreateChannelModal } from '@components/channels/createChannelModal';
-import { Globe } from 'iconoir-react';
-import Link from 'next/link';
+import { DEFAULT_CHANNELS } from '@stores/constants';
+
import { useState } from 'react';
export default function ChannelList() {
- const [list] = useState([]);
+ const [list] = useState(DEFAULT_CHANNELS);
return (
+ {/*
Browse channels
+ */}
{list.map((item) => (
-
+
))}
diff --git a/src/components/channels/channelListItem.tsx b/src/components/channels/channelListItem.tsx
index 6384d521..c687c811 100644
--- a/src/components/channels/channelListItem.tsx
+++ b/src/components/channels/channelListItem.tsx
@@ -3,8 +3,10 @@ import { ImageWithFallback } from '@components/imageWithFallback';
import { DEFAULT_AVATAR } from '@stores/constants';
+import { useChannelMetadata } from '@utils/hooks/useChannelMetadata';
+
export const ChannelListItem = ({ data }: { data: any }) => {
- const channel = JSON.parse(data.content);
+ const channel = useChannelMetadata(data.event_id, data.metadata);
return (
{
/>
-
{channel.name}
+ {channel?.name.toLowerCase()}
);
diff --git a/src/stores/constants.tsx b/src/stores/constants.tsx
index 103d9a8e..3dbb5742 100644
--- a/src/stores/constants.tsx
+++ b/src/stores/constants.tsx
@@ -2,3 +2,23 @@ export const APP_VERSION = '0.2.5';
export const DEFAULT_AVATAR = 'https://void.cat/d/KmypFh2fBdYCEvyJrPiN89.webp';
export const DEFAULT_CHANNEL_BANNER =
'https://bafybeiacwit7hjmdefqggxqtgh6ht5dhth7ndptwn2msl5kpkodudsr7py.ipfs.w3s.link/banner-1.jpg';
+export const DEFAULT_CHANNELS = [
+ {
+ event_id: 'e3cadf5beca1b2af1cddaa41a633679bedf263e3de1eb229c6686c50d85df753',
+ metadata: {
+ name: 'lume-general',
+ picture: 'https://void.cat/d/UNyxBmAh1MUx5gQTX95jyf.webp',
+ about: 'General channel for Lume',
+ },
+ created_at: 1681898574,
+ },
+ {
+ event_id: '25e5c82273a271cb1a840d0060391a0bf4965cafeb029d5ab55350b418953fbb',
+ metadata: {
+ about: '',
+ name: 'Nostr',
+ picture: 'https://cloudflare-ipfs.com/ipfs/QmTN4Eas9atUULVbEAbUU8cowhtvK7g3t7jfKztY7wc8eP?.png',
+ },
+ created_at: 1661333723,
+ },
+];
diff --git a/src/utils/hooks/useChannelMetadata.tsx b/src/utils/hooks/useChannelMetadata.tsx
index 926a4a53..8b36df8e 100644
--- a/src/utils/hooks/useChannelMetadata.tsx
+++ b/src/utils/hooks/useChannelMetadata.tsx
@@ -35,8 +35,12 @@ export const useChannelMetadata = (id: string, fallback: string) => {
}, []);
useEffect(() => {
- const json = JSON.parse(fallback);
- setMetadata(json);
+ if (typeof fallback === 'object') {
+ setMetadata(fallback);
+ } else {
+ const json = JSON.parse(fallback);
+ setMetadata(json);
+ }
// fetch kind 41
fetchMetadata();