-
-
Notifications
You must be signed in to change notification settings - Fork 835
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: recover local search component (#4104)
- Loading branch information
Showing
17 changed files
with
693 additions
and
120 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
13 changes: 8 additions & 5 deletions
13
...k/core/js/src/admin/components/Search.tsx → .../js/src/admin/components/GlobalSearch.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
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
61 changes: 61 additions & 0 deletions
61
framework/core/js/src/forum/components/DiscussionsSearchItem.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,61 @@ | ||
import app from '../../forum/app'; | ||
import Component, { ComponentAttrs } from '../../common/Component'; | ||
import Link from '../../common/components/Link'; | ||
import highlight from '../../common/helpers/highlight'; | ||
import Discussion from '../../common/models/Discussion'; | ||
import Post from '../../common/models/Post'; | ||
import type Mithril from 'mithril'; | ||
import ItemList from '../../common/utils/ItemList'; | ||
|
||
export interface DiscussionsSearchItemAttrs extends ComponentAttrs { | ||
query: string; | ||
discussion: Discussion; | ||
mostRelevantPost: Post; | ||
} | ||
|
||
export default class DiscussionsSearchItem extends Component<DiscussionsSearchItemAttrs> { | ||
query!: string; | ||
discussion!: Discussion; | ||
mostRelevantPost!: Post | null | undefined; | ||
|
||
oninit(vnode: Mithril.Vnode<DiscussionsSearchItemAttrs, this>) { | ||
super.oninit(vnode); | ||
|
||
this.query = this.attrs.query; | ||
this.discussion = this.attrs.discussion; | ||
this.mostRelevantPost = this.attrs.mostRelevantPost; | ||
} | ||
|
||
view() { | ||
return ( | ||
<li className="DiscussionSearchResult" data-index={'discussions' + this.discussion.id()}> | ||
<Link href={app.route.discussion(this.discussion, (this.mostRelevantPost && this.mostRelevantPost.number()) || 0)}> | ||
{this.viewItems().toArray()} | ||
</Link> | ||
</li> | ||
); | ||
} | ||
|
||
discussionTitle() { | ||
return this.discussion.title(); | ||
} | ||
|
||
mostRelevantPostContent() { | ||
return this.mostRelevantPost?.contentPlain(); | ||
} | ||
|
||
viewItems(): ItemList<Mithril.Children> { | ||
const items = new ItemList<Mithril.Children>(); | ||
|
||
items.add('discussion-title', <div className="DiscussionSearchResult-title">{highlight(this.discussionTitle(), this.query)}</div>, 90); | ||
|
||
!!this.mostRelevantPost && | ||
items.add( | ||
'most-relevant', | ||
<div className="DiscussionSearchResult-excerpt">{highlight(this.mostRelevantPostContent() ?? '', this.query, 100)}</div>, | ||
80 | ||
); | ||
|
||
return items; | ||
} | ||
} |
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.