|
1 | 1 | // Copyright 2020-2022 SubQuery Pte Ltd authors & contributors |
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
4 | | -import { useEffect, useState } from 'react'; |
5 | 4 | import { BsChatLeftDots } from 'react-icons/bs'; |
6 | | -import { IGetLatestTopics, useForumApis } from '@hooks/useForumApis'; |
7 | 5 | import { SubqlCard, Typography } from '@subql/components'; |
8 | | -import { renderAsync } from '@subql/react-hooks'; |
9 | | -import { parseError } from '@utils'; |
10 | | -import { Skeleton } from 'antd'; |
11 | 6 | import Link from 'antd/es/typography/Link'; |
12 | | -import dayjs from 'dayjs'; |
13 | 7 |
|
14 | | -export const ForumCard = () => { |
15 | | - const forumApis = useForumApis(); |
16 | | - const [topics, setTopics] = useState<IGetLatestTopics['topic_list']['topics']>([]); |
17 | | - |
18 | | - const getTopics = async () => { |
19 | | - const res = await forumApis.getLatestApi(); |
20 | | - |
21 | | - setTopics(res.slice(0, 5)); |
22 | | - }; |
| 8 | +const DISCORD_CHANNELS = [ |
| 9 | + { |
| 10 | + id: '1479054492501672007', |
| 11 | + title: 'General', |
| 12 | + url: 'https://discord.com/channels/796198414798028831/1479054492501672007', |
| 13 | + }, |
| 14 | + { |
| 15 | + id: '1479055557817008149', |
| 16 | + title: 'Subquery-foundation', |
| 17 | + url: 'https://discord.com/channels/796198414798028831/1479055557817008149', |
| 18 | + }, |
| 19 | + { |
| 20 | + id: '1479308156365701191', |
| 21 | + title: 'Technical-support', |
| 22 | + url: 'https://discord.com/channels/796198414798028831/1479308156365701191', |
| 23 | + }, |
| 24 | + { |
| 25 | + id: '1479308193426444348', |
| 26 | + title: 'Questions-feedback', |
| 27 | + url: 'https://discord.com/channels/796198414798028831/1479308193426444348', |
| 28 | + }, |
| 29 | + { |
| 30 | + id: '1479308237944651888', |
| 31 | + title: 'Mainnet-discussions', |
| 32 | + url: 'https://discord.com/channels/796198414798028831/1479308237944651888', |
| 33 | + }, |
| 34 | +]; |
23 | 35 |
|
24 | | - useEffect(() => { |
25 | | - getTopics(); |
26 | | - }, []); |
27 | | - |
28 | | - return renderAsync( |
29 | | - { |
30 | | - loading: !!!topics.length, |
31 | | - data: !topics.length ? undefined : topics, |
32 | | - }, |
33 | | - { |
34 | | - loading: () => <Skeleton active paragraph={{ rows: 14 }} style={{ marginTop: 30 }}></Skeleton>, |
35 | | - error: (e) => <>{parseError(e)}</>, |
36 | | - data: (topics) => { |
37 | | - return ( |
38 | | - <SubqlCard |
39 | | - title={ |
40 | | - <Typography style={{ display: 'flex', alignItems: 'flex-end' }}> |
41 | | - Forum |
42 | | - <BsChatLeftDots style={{ fontSize: 20, color: 'var(--sq-blue600)', marginLeft: 10 }}></BsChatLeftDots> |
| 36 | +export const ForumCard = () => { |
| 37 | + return ( |
| 38 | + <SubqlCard |
| 39 | + title={ |
| 40 | + <Typography style={{ display: 'flex', alignItems: 'flex-end' }}> |
| 41 | + Discord |
| 42 | + <BsChatLeftDots style={{ fontSize: 20, color: 'var(--sq-blue600)', marginLeft: 10 }}></BsChatLeftDots> |
| 43 | + </Typography> |
| 44 | + } |
| 45 | + width={302} |
| 46 | + > |
| 47 | + <div className="col-flex"> |
| 48 | + {DISCORD_CHANNELS.map((channel) => { |
| 49 | + return ( |
| 50 | + <Link |
| 51 | + key={channel.id} |
| 52 | + href={channel.url} |
| 53 | + className="col-flex" |
| 54 | + style={{ marginBottom: 16 }} |
| 55 | + target="_blank" |
| 56 | + rel="noopener noreferrer" |
| 57 | + > |
| 58 | + <Typography variant="medium" style={{ marginBottom: 0 }}> |
| 59 | + #{channel.title} |
43 | 60 | </Typography> |
44 | | - } |
45 | | - width={302} |
46 | | - > |
47 | | - <div className="col-flex"> |
48 | | - {topics.map((topic) => { |
49 | | - return ( |
50 | | - <Link |
51 | | - key={topic.slug} |
52 | | - href={`${import.meta.env.VITE_FORUM_DOMAIN}/t/${topic.slug}`} |
53 | | - className="col-flex" |
54 | | - style={{ marginBottom: 16 }} |
55 | | - > |
56 | | - <Typography variant="medium" style={{ marginBottom: 0 }}> |
57 | | - {topic.title} |
58 | | - </Typography> |
59 | | - <Typography variant="small" type="secondary" style={{ marginTop: 8, marginBottom: 0 }}> |
60 | | - {dayjs(topic.last_posted_at || topic.created_at) |
61 | | - .utc(true) |
62 | | - .fromNow()} |
63 | | - </Typography> |
64 | | - </Link> |
65 | | - ); |
66 | | - })} |
67 | | - <Link href="https://forum.subquery.network/c/kepler-network/16">View Forum</Link> |
68 | | - </div> |
69 | | - </SubqlCard> |
70 | | - ); |
71 | | - }, |
72 | | - }, |
| 61 | + </Link> |
| 62 | + ); |
| 63 | + })} |
| 64 | + <Link href="https://discord.gg/subquery" target="_blank" rel="noopener noreferrer"> |
| 65 | + Join Discord |
| 66 | + </Link> |
| 67 | + </div> |
| 68 | + </SubqlCard> |
73 | 69 | ); |
74 | 70 | }; |
0 commit comments