Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
24 changes: 20 additions & 4 deletions apps/obsidian/src/components/RelationshipTypeSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@ const RelationshipTypeSettings = () => {
);
const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false);

const handleRelationTypeChange = async (
const handleRelationTypeChange = (
index: number,
field: keyof DiscourseRelationType,
value: string,
): Promise<void> => {
): void => {
const updatedRelationTypes = [...relationTypes];
if (!updatedRelationTypes[index]) {
const newId = generateUid("rel");
updatedRelationTypes[index] = { id: newId, label: "", complement: "" };
updatedRelationTypes[index] = {
id: newId,
label: "",
complement: "",
color: "#000000",
};
}

updatedRelationTypes[index][field] = value;
Expand All @@ -37,6 +42,7 @@ const RelationshipTypeSettings = () => {
id: newId,
label: "",
complement: "",
color: "#000000",
},
];
setRelationTypes(updatedRelationTypes);
Expand All @@ -47,6 +53,7 @@ const RelationshipTypeSettings = () => {
const relationType = relationTypes[index] || {
label: "Unnamed",
complement: "",
color: "#000000",
};
const modal = new ConfirmationModal(plugin.app, {
title: "Delete Relation Type",
Expand Down Expand Up @@ -77,7 +84,7 @@ const RelationshipTypeSettings = () => {

const handleSave = async (): Promise<void> => {
for (const relType of relationTypes) {
if (!relType.id || !relType.label || !relType.complement) {
if (!relType.id || !relType.label || !relType.complement || !relType.color) {
new Notice("All fields are required for relation types.");
return;
}
Expand Down Expand Up @@ -125,6 +132,15 @@ const RelationshipTypeSettings = () => {
}
className="flex-1"
/>
<input
type="color"
value={relationType.color}
onChange={(e) =>
handleRelationTypeChange(index, "color", e.target.value)
}
className="w-12 h-8 rounded border"
title="Relation color"
/>
<button
onClick={() => confirmDeleteRelationType(index)}
className="mod-warning p-2"
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 @@ -26,16 +26,19 @@ export const DEFAULT_RELATION_TYPES: Record<string, DiscourseRelationType> = {
id: generateUid("relation"),
label: "supports",
complement: "is supported by",
color: "#008000",
},
opposes: {
id: generateUid("relation"),
label: "opposes",
complement: "is opposed by",
color: "#FF0000",
},
informs: {
id: generateUid("relation"),
label: "informs",
complement: "is informed by",
color: "#0000FF",
},
};

Expand Down
1 change: 1 addition & 0 deletions apps/obsidian/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type DiscourseRelationType = {
id: string;
label: string;
complement: string;
color: string;
};

export type DiscourseRelation = {
Expand Down
8 changes: 4 additions & 4 deletions apps/roam/src/components/DiscourseNodeSearchMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ const NodeSearchMenu = ({
}, [filteredTypes, searchResults]);

const onSelect = useCallback(
(item: Result) => {
waitForBlock(blockUid, textarea.value).then(() => {
async (item: Result) => {
void waitForBlock(blockUid, textarea.value).then(() => {
onClose();

setTimeout(() => {
Expand All @@ -205,11 +205,11 @@ const NodeSearchMenu = ({
const pageRef = `[[${item.text}]]`;

const newText = `${prefix}${pageRef}${suffix}`;
updateBlock({ uid: blockUid, text: newText }).then(() => {
void updateBlock({ uid: blockUid, text: newText }).then(() => {
const newCursorPosition = triggerPosition + pageRef.length;

if (window.roamAlphaAPI.ui.setBlockFocusAndSelection) {
window.roamAlphaAPI.ui.setBlockFocusAndSelection({
void window.roamAlphaAPI.ui.setBlockFocusAndSelection({
location: {
"block-uid": blockUid,
"window-id": windowId,
Expand Down