Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
feat: refine search
Browse files Browse the repository at this point in the history
  • Loading branch information
zxch3n committed Apr 22, 2020
1 parent eac37b7 commit 23c40ff
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
9 changes: 8 additions & 1 deletion src/renderer/components/Kanban/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ export const Card: FC<Props> = React.memo((props: Props) => {
return props.content;
}

const reg = new RegExp(props.searchReg, 'gimsu');
let reg: undefined | RegExp;
try {
reg = new RegExp(props.searchReg, 'gimsu');
} catch (e) {}
if (!reg) {
return props.content;
}

const oldContent = props.content;
let newContent = '';
let lastEnd = 0;
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/components/Kanban/Card/CardEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const _CardInDetail: FC<Props> = React.memo((props: Props) => {
actualTime: undefined,
} as FormData);
}
}, [card]);
}, [card, visible]);

const onDelete = React.useCallback(() => {
if (!card) {
Expand All @@ -80,7 +80,7 @@ const _CardInDetail: FC<Props> = React.memo((props: Props) => {

const saveValues = ({ title, content, estimatedTime, actualTime }: FormData) => {
const time = estimatedTime || 0;
setCardContent(content);
setCardContent(content || '');
if (!card) {
// Creating
const _id = shortid.generate();
Expand Down Expand Up @@ -123,7 +123,7 @@ const _CardInDetail: FC<Props> = React.memo((props: Props) => {
setShowMarkdownPreview(false);
} else {
validateFields((err: Error, values: FormData) => {
setCardContent(values.content);
setCardContent(values.content || '');
setShowMarkdownPreview(true);
});
}
Expand Down Expand Up @@ -172,7 +172,7 @@ const _CardInDetail: FC<Props> = React.memo((props: Props) => {
minHeight: 120,
}}
dangerouslySetInnerHTML={{
__html: formatMarkdown(cardContent),
__html: formatMarkdown(cardContent || ''),
}}
/>
</TabPane>
Expand Down
18 changes: 15 additions & 3 deletions src/renderer/components/Kanban/List/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ interface Props extends ListType, InputProps, ListActionTypes, KanbanActionTypes

export const List: FC<Props> = React.memo((props: Props) => {
const { focused = false, searchReg, cards, cardsState, done = false } = props;
const reg = searchReg ? new RegExp(searchReg, 'gimsu') : undefined;
let reg: RegExp | undefined;
try {
reg = searchReg ? new RegExp(searchReg, 'gimsu') : undefined;
} catch (e) {}
const [estimatedTimeSum, actualTimeSum] = props.cards.reduce(
(l: [number, number], r: string) => {
return [
Expand All @@ -132,6 +135,7 @@ export const List: FC<Props> = React.memo((props: Props) => {
reg === undefined
? cards
: cards.filter((id) => {
if (!reg) return true;
const card = cardsState[id];
return card.title.match(reg) || card.content.match(reg);
});
Expand Down Expand Up @@ -220,8 +224,16 @@ export const List: FC<Props> = React.memo((props: Props) => {
<span className="list-head-text">
<h1>{props.title}</h1>
<span>
{props.cards.length} Card
{props.cards.length > 1 ? 's ' : ' '}
{reg == null ? (
<span>
{props.cards.length} Card
{props.cards.length > 1 ? 's ' : ' '}
</span>
) : (
<span>
{filteredCards.length} / {props.cards.length}
</span>
)}
{overallTimeInfo}
</span>
</span>
Expand Down
16 changes: 10 additions & 6 deletions src/renderer/components/Kanban/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Icon } from 'antd';

const Bar = styled.div`
position: fixed;
top: 60px;
top: 90px;
right: 30px;
z-index: 10000;
box-shadow: 2px 2px 4px 4px rgba(40, 40, 40, 0.2);
Expand Down Expand Up @@ -54,17 +54,21 @@ const _SearchBar: FC<Props> = (props: Props) => {
});
}, []);

const quit = React.useCallback(() => {
const hide = () => {
props.setIsSearching(false);
}, []);
};

const quit = React.useCallback(() => {
props.setReg(undefined);
hide();
}, [props.setIsSearching, props.setReg]);

const onKeyDown = React.useCallback(
(event: KeyboardEvent<any>) => {
if (event.keyCode === 27) {
props.setReg(undefined);
quit();
} else if (event.keyCode === 13) {
quit();
hide();
}
},
[props.setIsSearching]
Expand All @@ -82,7 +86,7 @@ const _SearchBar: FC<Props> = (props: Props) => {
<input
// @ts-ignore
ref={ref}
placeholder="input search text"
placeholder="Search by RegExp"
onKeyDown={onKeyDown}
onChange={onChange}
value={props.reg}
Expand Down

0 comments on commit 23c40ff

Please sign in to comment.