Skip to content

Commit 5a30b3e

Browse files
committed
make search results clickable
1 parent 881dff9 commit 5a30b3e

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

src/packages/frontend/chat/filter-messages.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ function getContent(message: ChatMessageTyped, userMap): string {
9090
const author_id = first.get("author_id");
9191
const user = userMap?.get(author_id);
9292
if (user != null) {
93-
content += " " + user.get("first_name") + " " + user.get("last_name");
93+
content =
94+
user.get("first_name") + " " + user.get("last_name") + "\n\n" + content;
9495
}
9596
return content;
9697
}

src/packages/frontend/client/console.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ you have to change the context to *top*! See
2424
http://stackoverflow.com/questions/3275816/debugging-iframes-with-chrome-developer-tools/8581276#8581276
2525
*/
2626

27-
declare const DEBUG; // this comes from webpack.
27+
declare const DEBUG; // this comes from rspack.
2828
console.log("DEBUG = ", DEBUG);
2929

3030
import { IS_TOUCH } from "../feature";

src/packages/frontend/frame-editors/chat-editor/search.tsx

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { throttle } from "lodash";
1616
import useSearchIndex from "./use-search-index";
1717
import ShowError from "@cocalc/frontend/components/error";
1818
import { Icon } from "@cocalc/frontend/components/icon";
19+
import StaticMarkdown from "@cocalc/frontend/editors/slate/static-markdown";
20+
import { TimeAgo } from "@cocalc/frontend/components";
1921

2022
interface Props {
2123
font_size: number;
@@ -86,6 +88,7 @@ function Search({ font_size, desc }: Props) {
8688
style={{ marginBottom: "15px" }}
8789
/>
8890
<Input.Search
91+
autoFocus
8992
allowClear
9093
placeholder="Search for messages..."
9194
value={search}
@@ -96,9 +99,41 @@ function Search({ font_size, desc }: Props) {
9699
}}
97100
/>
98101
</Card>
99-
<pre className="smc-vfill" style={{ overflow: "auto" }}>
100-
{JSON.stringify(result, undefined, 2)}
101-
</pre>
102+
<div className="smc-vfill">
103+
<div style={{ overflow: "auto", padding: "15px" }}>
104+
{result?.hits?.map((hit) => (
105+
<SearchResult key={hit.id} hit={hit} actions={actions} />
106+
))}
107+
{result?.hits == null && search?.trim() && <div>No hits</div>}
108+
</div>
109+
</div>
110+
</div>
111+
);
112+
}
113+
114+
function SearchResult({ hit, actions }) {
115+
const { document } = hit;
116+
return (
117+
<div
118+
style={{
119+
cursor: "pointer",
120+
margin: "5px 0",
121+
padding: "5px",
122+
border: "1px solid #ccc",
123+
background: "#f8f8f8",
124+
borderRadius: "5px",
125+
maxHeight: "100px",
126+
overflow: "hidden",
127+
}}
128+
onClick={() => {
129+
actions.gotoFragment({ chat: document.time });
130+
}}
131+
>
132+
<TimeAgo style={{ float: "right", color: "#888" }} date={document.time} />
133+
<StaticMarkdown
134+
value={document.message}
135+
style={{ marginBottom: "-10px" /* account for <p> */ }}
136+
/>
102137
</div>
103138
);
104139
}

src/packages/frontend/frame-editors/code-editor/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2969,7 +2969,7 @@ export class Actions<
29692969
if (state != "ready" && !(await this.wait_until_syncdoc_ready(syncdoc))) {
29702970
return "";
29712971
}
2972-
const frameId = this.show_focused_frame_of_type(type);
2972+
const frameId = this.show_focused_frame_of_type(type, "col", true);
29732973
if (state != "ready" && frameId) {
29742974
// TODO: temporary hack until we have gotoFragment
29752975
// as part of constructor!

0 commit comments

Comments
 (0)