pass contextItems around a bit more
This commit is contained in:
parent
9b529c9934
commit
00aaba6479
4 changed files with 18 additions and 13 deletions
|
|
@ -105,6 +105,7 @@ function StepContainer(props: StepContainerProps) {
|
|||
<StyledMarkdownPreview
|
||||
isRenderingInStepContainer
|
||||
source={stripImages(props.item.message.content)}
|
||||
contextItems={props.item.contextItems}
|
||||
/>
|
||||
)}
|
||||
</ContentDiv>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { NodeViewWrapper } from "@tiptap/react";
|
||||
import { ContextItemWithId } from "core";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { vscBadgeBackground } from "..";
|
||||
import { RootState } from "../../redux/store";
|
||||
import CodeSnippetPreview from "../markdown/CodeSnippetPreview";
|
||||
import { useSelector } from "react-redux";
|
||||
import { RootState } from "../../redux/store";
|
||||
|
||||
export const CodeBlockComponent = ({
|
||||
node,
|
||||
|
|
@ -13,15 +13,17 @@ export const CodeBlockComponent = ({
|
|||
updateAttributes,
|
||||
}: any) => {
|
||||
const item: ContextItemWithId = node.attrs.item;
|
||||
const contextItems = useSelector(
|
||||
(store: RootState) =>
|
||||
store.state.history[store.state.history.length - 1].contextItems,
|
||||
);
|
||||
const isFirstContextItem = item.id === contextItems[0].id;
|
||||
|
||||
// const contextItems = useSelector(
|
||||
// (state: RootState) => state.state.history[0]?.contextItems[0]?.id,
|
||||
// );
|
||||
return (
|
||||
<NodeViewWrapper className="code-block-with-content" as="p">
|
||||
<CodeSnippetPreview
|
||||
borderColor={
|
||||
item.id === contextItems[0]?.id
|
||||
isFirstContextItem
|
||||
? "#d0d"
|
||||
: selected
|
||||
? vscBadgeBackground
|
||||
|
|
|
|||
|
|
@ -124,6 +124,7 @@ function CodeSnippetPreview(props: CodeSnippetPreviewProps) {
|
|||
source={`${fence}${getMarkdownLanguageTagForFile(
|
||||
props.item.description.split(" ")[0],
|
||||
)} ${props.item.description}\n${content}\n${fence}`}
|
||||
contextItems={[props.item]}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -236,13 +236,14 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
|
|||
code: ({ node, ...codeProps }) => {
|
||||
const content = getCodeChildrenContent(codeProps.children);
|
||||
|
||||
const ctxItem = props.contextItems?.find((ctxItem) =>
|
||||
ctxItem.uri?.value.includes(content),
|
||||
);
|
||||
|
||||
if (ctxItem) {
|
||||
const rif = ctxItemToRifWithContents(ctxItem);
|
||||
return <FilenameLink rif={rif} />;
|
||||
if (props.contextItems) {
|
||||
const ctxItem = props.contextItems.find((ctxItem) =>
|
||||
ctxItem.uri?.value.includes(content),
|
||||
);
|
||||
if (ctxItem) {
|
||||
const rif = ctxItemToRifWithContents(ctxItem);
|
||||
return <FilenameLink rif={rif} />;
|
||||
}
|
||||
}
|
||||
|
||||
return <code {...codeProps}>{codeProps.children}</code>;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue