-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2da3a3f
commit 4cc140e
Showing
24 changed files
with
735 additions
and
121 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
import { ArrowLeftOutlined, EnterOutlined, SearchOutlined } from '@ant-design/icons' | ||
import { Navbar, NavbarCenter } from '@renderer/components/app/Navbar' | ||
import { Message, Topic } from '@renderer/types' | ||
import { Divider, Input } from 'antd' | ||
import { last } from 'lodash' | ||
import { FC, useState } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import styled from 'styled-components' | ||
|
||
import SearchMessage from './components/SearchMessage' | ||
import SearchResults from './components/SearchResults' | ||
import TopicMessages from './components/TopicMessages' | ||
import TopicsHistory from './components/TopicsHistory' | ||
|
||
type Route = 'topics' | 'topic' | 'search' | 'message' | ||
|
||
let _search = '' | ||
let _stack: Route[] = ['topics'] | ||
let _topic: Topic | undefined | ||
let _message: Message | undefined | ||
|
||
const TopicsPage: FC = () => { | ||
const { t } = useTranslation() | ||
const [search, setSearch] = useState(_search) | ||
const [stack, setStack] = useState<Route[]>(_stack) | ||
const [topic, setTopic] = useState<Topic | undefined>(_topic) | ||
const [message, setMessage] = useState<Message | undefined>(_message) | ||
|
||
_search = search | ||
_stack = stack | ||
_topic = topic | ||
_message = message | ||
|
||
const goBack = () => { | ||
const _stack = [...stack] | ||
const route = _stack.pop() | ||
setStack(_stack) | ||
route === 'search' && setSearch('') | ||
route === 'topic' && setTopic(undefined) | ||
route === 'message' && setMessage(undefined) | ||
} | ||
|
||
const onSearch = () => { | ||
setStack(['topics', 'search']) | ||
setTopic(undefined) | ||
} | ||
|
||
const onTopicClick = (topic: Topic) => { | ||
setStack((prev) => [...prev, 'topic']) | ||
setTopic(topic) | ||
} | ||
|
||
const onMessageClick = (message: Message) => { | ||
setStack(['topics', 'search', 'message']) | ||
setMessage(message) | ||
} | ||
|
||
const isShow = (route: Route) => (last(stack) === route ? 'flex' : 'none') | ||
|
||
return ( | ||
<Container> | ||
<Navbar> | ||
<NavbarCenter style={{ borderRight: 'none', justifyContent: 'flex-start' }}>{t('history.title')} </NavbarCenter> | ||
</Navbar> | ||
<ContentContainer id="content-container"> | ||
<Header> | ||
{stack.length > 1 && ( | ||
<HeaderLeft> | ||
<MenuIcon onClick={goBack}> | ||
<ArrowLeftOutlined /> | ||
</MenuIcon> | ||
</HeaderLeft> | ||
)} | ||
<SearchInput | ||
placeholder={t('history.search.placeholder')} | ||
type="search" | ||
value={search} | ||
allowClear | ||
onChange={(e) => setSearch(e.target.value.trimStart())} | ||
suffix={search.length >= 2 ? <EnterOutlined /> : <SearchOutlined />} | ||
onPressEnter={onSearch} | ||
/> | ||
</Header> | ||
<Divider style={{ margin: 0 }} /> | ||
<TopicsHistory keywords={search} onClick={onTopicClick as any} style={{ display: isShow('topics') }} /> | ||
<TopicMessages topic={topic} style={{ display: isShow('topic') }} /> | ||
<SearchResults | ||
keywords={search} | ||
onMessageClick={onMessageClick} | ||
onTopicClick={onTopicClick} | ||
style={{ display: isShow('search') }} | ||
/> | ||
<SearchMessage message={message} style={{ display: isShow('message') }} /> | ||
</ContentContainer> | ||
</Container> | ||
) | ||
} | ||
|
||
const Container = styled.div` | ||
display: flex; | ||
flex: 1; | ||
flex-direction: column; | ||
height: 100%; | ||
` | ||
|
||
const ContentContainer = styled.div` | ||
display: flex; | ||
flex: 1; | ||
flex-direction: column; | ||
align-items: center; | ||
height: 100%; | ||
overflow: hidden; | ||
` | ||
|
||
const Header = styled.div` | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: center; | ||
padding: 8px 20px; | ||
width: 100%; | ||
position: relative; | ||
` | ||
|
||
const HeaderLeft = styled.div` | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
position: absolute; | ||
top: 8px; | ||
left: 15px; | ||
` | ||
|
||
const MenuIcon = styled.div` | ||
cursor: pointer; | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: center; | ||
align-items: center; | ||
width: 36px; | ||
height: 36px; | ||
border-radius: 50%; | ||
&:hover { | ||
background-color: var(--color-background-mute); | ||
.anticon { | ||
color: var(--color-text-1); | ||
} | ||
} | ||
` | ||
|
||
const SearchInput = styled(Input)` | ||
border-radius: 30px; | ||
width: 800px; | ||
height: 36px; | ||
` | ||
|
||
export default TopicsPage |
38 changes: 38 additions & 0 deletions
38
src/renderer/src/pages/history/components/SearchMessage.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,38 @@ | ||
import { default as MessageItem } from '@renderer/pages/home/Messages/Message' | ||
import { Message } from '@renderer/types' | ||
import { FC } from 'react' | ||
import styled from 'styled-components' | ||
|
||
interface Props extends React.HTMLAttributes<HTMLDivElement> { | ||
message?: Message | ||
} | ||
|
||
const SearchMessage: FC<Props> = ({ message, ...props }) => { | ||
if (!message) { | ||
return null | ||
} | ||
|
||
return ( | ||
<MessagesContainer {...props}> | ||
<ContainerWrapper style={{ paddingTop: 30, paddingBottom: 30 }}> | ||
<MessageItem message={message} showMenu={false} /> | ||
</ContainerWrapper> | ||
</MessagesContainer> | ||
) | ||
} | ||
|
||
const MessagesContainer = styled.div` | ||
width: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
overflow-y: scroll; | ||
` | ||
|
||
const ContainerWrapper = styled.div` | ||
width: 800px; | ||
display: flex; | ||
flex-direction: column; | ||
` | ||
|
||
export default SearchMessage |
Oops, something went wrong.