Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion apps/obsidian/src/components/DiscourseContextView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ const DiscourseContext = ({ activeFile }: DiscourseContextProps) => {
return (
<>
<div className="mb-6">
<div className="text-md mb-2 font-bold">
<div className="text-md mb-2 flex items-center gap-2 font-bold">
{nodeType.color && (
<div
className="h-4 w-4 rounded-full"
style={{ backgroundColor: nodeType.color }}
/>
)}
{nodeType.name || "Unnamed Node Type"}
</div>

Expand Down
9 changes: 8 additions & 1 deletion apps/obsidian/src/components/NodeTypeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ export class NodeTypeModal extends SuggestModal<DiscourseNode> {
}

renderSuggestion(nodeType: DiscourseNode, el: HTMLElement) {
el.createEl("div", { text: nodeType.name });
const container = el.createDiv({ cls: "flex items-center gap-2" });
if (nodeType.color) {
container.createDiv({
cls: "h-4 w-4 rounded-full",
attr: { style: `background-color: ${nodeType.color};` },
});
}
container.createDiv({ text: nodeType.name });
}

async onChooseSuggestion(nodeType: DiscourseNode) {
Expand Down
40 changes: 37 additions & 3 deletions apps/obsidian/src/components/NodeTypeSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { DiscourseNode } from "~/types";
import { ConfirmationModal } from "./ConfirmationModal";
import { getTemplateFiles, getTemplatePluginInfo } from "~/utils/templates";

type EditableFieldKey = keyof Omit<DiscourseNode, "id" | "shortcut" | "color">;
type EditableFieldKey = keyof Omit<DiscourseNode, "id" | "shortcut">;

type BaseFieldConfig = {
key: EditableFieldKey;
label: string;
description: string;
required?: boolean;
type: "text" | "select";
type: "text" | "select" | "color";
placeholder?: string;
validate?: (
value: string,
Expand Down Expand Up @@ -68,6 +68,13 @@ const FIELD_CONFIGS: Record<EditableFieldKey, BaseFieldConfig> = {
type: "select",
required: false,
},
color: {
key: "color",
label: "Color",
description: "The color to use for this node type",
type: "color",
required: false,
},
};

const FIELD_CONFIG_ARRAY = Object.values(FIELD_CONFIGS);
Expand All @@ -92,6 +99,23 @@ const TextField = ({
/>
);

const ColorField = ({
value,
error,
onChange,
}: {
value: string;
error?: string;
onChange: (value: string) => void;
}) => (
<input
type="color"
value={value || "#000000"}
onChange={(e) => onChange(e.target.value)}
className={`h-8 w-20 ${error ? "input-error" : ""}`}
/>
);

const TemplateField = ({
value,
error,
Expand Down Expand Up @@ -367,6 +391,8 @@ const NodeTypeSettings = () => {
templateConfig={templateConfig}
templateFiles={templateFiles}
/>
) : fieldConfig.type === "color" ? (
<ColorField value={value} error={error} onChange={handleChange} />
) : (
<TextField
fieldConfig={fieldConfig}
Expand All @@ -391,7 +417,15 @@ const NodeTypeSettings = () => {
onClick={() => startEditing(index)}
>
<div className="flex items-center justify-between">
<span className="font-medium">{nodeType.name}</span>
<div className="flex items-center gap-2">
{nodeType.color && (
<div
className="h-4 w-4 rounded-full"
style={{ backgroundColor: nodeType.color }}
/>
)}
<span>{nodeType.name}</span>
</div>
<div className="flex gap-2">
<button
className="icon-button"
Expand Down
3 changes: 3 additions & 0 deletions apps/obsidian/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ export const DEFAULT_NODE_TYPES: Record<string, DiscourseNode> = {
id: generateUid("node"),
name: "Question",
format: "QUE - {content}",
color: "#99890e",
},
Claim: {
id: generateUid("node"),
name: "Claim",
format: "CLM - {content}",
color: "#7DA13E",
},
Evidence: {
id: generateUid("node"),
name: "Evidence",
format: "EVD - {content}",
color: "#DB134A",
},
};
export const DEFAULT_RELATION_TYPES: Record<string, DiscourseRelationType> = {
Expand Down