-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added Topics in popup to mute unrelated topics
- Loading branch information
1 parent
7bc1802
commit 3cfaef3
Showing
12 changed files
with
249 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/components/SourcesTableModal/SourcesView/Topics/Table/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { Table as MaterialTable, TableRow } from '@mui/material' | ||
import React from 'react' | ||
import { MdCheckCircle, MdCancel } from 'react-icons/md' | ||
import styled from 'styled-components' | ||
import FilterOffIcon from '~/components/Icons/FilterOffIcon' | ||
import { Flex } from '~/components/common/Flex' | ||
import { Text } from '~/components/common/Text' | ||
import { putNodeData } from '~/network/fetchSourcesData' | ||
// import { useDataStore } from '~/stores/useDataStore' | ||
import { Topic } from '~/types' | ||
import { colors } from '~/utils/colors' | ||
import { StyledTableCell, StyledTableHead, StyledTableRow } from '../../common' | ||
import { TopicTableProps } from '../../types' | ||
|
||
const Table: React.FC<TopicTableProps> = ({ data, showMuted }) => { | ||
// const setSources = useDataStore((s) => s.setQueuedSources) | ||
|
||
const handleMute = async (refId: string, shouldMute: boolean) => { | ||
if (data?.length) { | ||
try { | ||
await putNodeData({ ref_id: refId, node_name: 'muted_topic', node_value: shouldMute }) | ||
|
||
// setSources(data.filter((i) => i.ref_id !== id)) | ||
} catch (error) { | ||
console.warn(error) | ||
} | ||
} | ||
} | ||
|
||
return !data?.length ? ( | ||
<Flex> | ||
<Text>There is not any results for selected filters</Text> | ||
<FilterOffIcon /> | ||
</Flex> | ||
) : ( | ||
<MaterialTable component="table"> | ||
<StyledTableHead> | ||
<TableRow component="tr"> | ||
<StyledTableCell className="empty" /> | ||
<StyledTableCell>Type</StyledTableCell> | ||
<StyledTableCell>{showMuted ? 'Unmute' : 'Mute'}</StyledTableCell> | ||
</TableRow> | ||
</StyledTableHead> | ||
{data?.length && ( | ||
<tbody> | ||
{data?.map((i: Topic) => ( | ||
<StyledTableRow key={i.topic}> | ||
<StyledTableCell className="empty" /> | ||
<StyledTableCell>{i.topic}</StyledTableCell> | ||
|
||
<StyledTableCell className="cell-center"> | ||
<Flex direction="row" justify="space-between"> | ||
<div className="approve-wrapper"> | ||
{i.muted_topic ? ( | ||
<IconWrapper className="centered" onClick={() => handleMute(i.ref_id, false)}> | ||
<MdCheckCircle color={colors.primaryGreen} fontSize={24} /> | ||
</IconWrapper> | ||
) : ( | ||
<IconWrapper className="centered" onClick={() => handleMute(i.ref_id, true)}> | ||
<MdCancel color={colors.primaryRed} fontSize={24} /> | ||
</IconWrapper> | ||
)} | ||
</div> | ||
</Flex> | ||
</StyledTableCell> | ||
<StyledTableCell className="empty" /> | ||
</StyledTableRow> | ||
))} | ||
</tbody> | ||
)} | ||
</MaterialTable> | ||
) | ||
} | ||
|
||
export default Table | ||
|
||
const IconWrapper = styled(Flex)` | ||
width: 20px; | ||
height: 20px; | ||
border-radius: 50%; | ||
cursor: pointer; | ||
background: transparent; | ||
color: ${colors.lightBlue500}; | ||
&.centered { | ||
margin: 0 auto; | ||
} | ||
& + & { | ||
margin-left: 4px; | ||
} | ||
` |
97 changes: 97 additions & 0 deletions
97
src/components/SourcesTableModal/SourcesView/Topics/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { useEffect, useState } from 'react' | ||
import { ClipLoader } from 'react-spinners' | ||
import styled from 'styled-components' | ||
import { Flex } from '~/components/common/Flex' | ||
import { Text } from '~/components/common/Text' | ||
import { Pill } from '~/components/common/Pill' | ||
import { getTopicsData } from '~/network/fetchSourcesData' | ||
import { useDataStore } from '~/stores/useDataStore' | ||
import { FetchTopicResponse } from '~/types' | ||
import { colors } from '~/utils/colors' | ||
import { Heading } from '../common' | ||
import Table from './Table' | ||
|
||
export const TopicSources = () => { | ||
const [loading, setLoading] = useState(true) | ||
const [showMuted, setShowMuted] = useState(false) | ||
const [topics, setTopics] = useDataStore((s) => [s.topics, s.setTopics]) | ||
|
||
useEffect(() => { | ||
const init = async () => { | ||
setLoading(true) | ||
|
||
try { | ||
const mutedParam = showMuted ? 'True' : 'False' | ||
const data: FetchTopicResponse = await getTopicsData({ muted: mutedParam }) | ||
|
||
setTopics(data.data) | ||
} catch (error) { | ||
console.warn(error) | ||
} finally { | ||
setLoading(false) | ||
} | ||
} | ||
|
||
init() | ||
}, [setTopics, showMuted]) | ||
|
||
return ( | ||
<Wrapper align="stretch" direction="column" justify="flex-end"> | ||
<Heading align="flex-start" justify="space-between"> | ||
<Text className="title">Topics</Text> | ||
</Heading> | ||
<Pill | ||
className="booster__pill" | ||
onClick={() => setShowMuted(!showMuted)} | ||
style={{ marginLeft: '30px', marginBottom: '10px', padding: '5px 10px 5px 10px', width: 'fit-content' }} | ||
> | ||
{loading ? ( | ||
<ClipLoader color={colors.white} /> | ||
) : ( | ||
<Flex align="center" direction="row" justify="center"> | ||
<div style={{ fontSize: 10 }}>Show {showMuted ? 'Unmuted' : 'Muted'}</div> | ||
</Flex> | ||
)} | ||
</Pill> | ||
|
||
<TableWrapper align="center" justify={loading ? 'center' : 'flex-start'}> | ||
{loading ? <ClipLoader color={colors.white} /> : <Table data={topics} showMuted={showMuted} />} | ||
</TableWrapper> | ||
</Wrapper> | ||
) | ||
} | ||
|
||
const Wrapper = styled(Flex)` | ||
flex: 1; | ||
.title { | ||
margin-bottom: 32px; | ||
font-size: 20px; | ||
color: ${colors.white}; | ||
font-family: Barlow; | ||
font-size: 22px; | ||
font-style: normal; | ||
font-weight: 600; | ||
line-height: normal; | ||
} | ||
.subtitle { | ||
color: ${colors.GRAY3}; | ||
font-family: Barlow; | ||
font-size: 13px; | ||
font-style: normal; | ||
font-weight: 400; | ||
line-height: normal; | ||
} | ||
& .filters { | ||
overflow-x: auto; | ||
} | ||
` | ||
|
||
const TableWrapper = styled(Flex)` | ||
min-height: 0; | ||
overflow: auto; | ||
flex: 1; | ||
width: 100%; | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.