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
4 changes: 4 additions & 0 deletions src/components/routes/task/api/taskApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export const createSubTasks = async (
content_type: string;
display_order: number;
duration?: string;
source_text_id?: string | null;
pecha_segment_id?: string | null;
}[],
) => {
const { data } = await axiosInstance.post(
Expand All @@ -67,6 +69,8 @@ export const updateSubTasks = async (
content_type: string;
display_order: number;
duration?: string;
source_text_id?: string | null;
pecha_segment_id?: string | null;
}[],
) => {
await axiosInstance.put(
Expand Down
22 changes: 20 additions & 2 deletions src/components/routes/task/components/view/TaskForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ const TaskForm = ({
display_order: index + 1,
...(subTask.content_type === "VIDEO" &&
subTask.duration && { duration: subTask.duration }),
...(subTask.content_type === "SOURCE_REFERENCE" && {
source_text_id: subTask.source_text_id || null,
pecha_segment_id: subTask.pecha_segment_id || null,
}),
}));
await createSubTasks(taskResponse.id, subTasksPayload);
}
Expand Down Expand Up @@ -109,6 +113,10 @@ const TaskForm = ({
display_order: index + 1,
...(subTask.content_type === "VIDEO" &&
subTask.duration && { duration: subTask.duration }),
...(subTask.content_type === "SOURCE_REFERENCE" && {
source_text_id: subTask.source_text_id || null,
pecha_segment_id: subTask.pecha_segment_id || null,
}),
}));
await updateSubTasks(editingTask.id, subTasksPayload);
},
Expand Down Expand Up @@ -182,6 +190,8 @@ const TaskForm = ({
id: data.id,
content_type: "SOURCE_REFERENCE",
content: data.content,
source_text_id: data.source_text_id || null,
pecha_segment_id: data.pecha_segment_id || null,
};
default:
return {
Expand All @@ -195,7 +205,13 @@ const TaskForm = ({
}
}, [editingTask?.id, selectedDay, taskDetails?.id]);

const handleAddSubTask = (content_type: any, sourceContent?: string) => {
interface SourceData {
content: string;
segment_id: string;
text_id: string;
}

const handleAddSubTask = (content_type: any, sourceData?: SourceData) => {
let newSubTask: SubTask;

switch (content_type) {
Expand Down Expand Up @@ -233,7 +249,9 @@ const TaskForm = ({
newSubTask = {
id: null,
content_type: "SOURCE_REFERENCE",
content: sourceContent || "",
content: sourceData?.content || "",
source_text_id: sourceData?.text_id || null,
pecha_segment_id: sourceData?.segment_id || null,
};
break;
}
Expand Down
12 changes: 9 additions & 3 deletions src/components/ui/molecules/content-sub/ContentTypeSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ import pechaIcon from "@/assets/icon/pecha_icon.png";
import { useState } from "react";
import { SourceSelectorSheet } from "../webuddhist-source/SourceSelectorSheet";

interface SourceData {
content: string;
segment_id: string;
text_id: string;
}

interface ContentTypeSelectorProps {
onSelectType: (
type: "IMAGE" | "VIDEO" | "AUDIO" | "TEXT" | "SOURCE_REFERENCE",
sourceContent?: string,
sourceData?: SourceData,
) => void;
}

Expand Down Expand Up @@ -53,8 +59,8 @@ export const ContentTypeSelector = ({
}
};

const handleAddSource = (sourceContent: string) => {
onSelectType("SOURCE_REFERENCE", sourceContent);
const handleAddSource = (sourceData: SourceData) => {
onSelectType("SOURCE_REFERENCE", sourceData);
setIsSourceSheetOpen(false);
};

Expand Down
2 changes: 2 additions & 0 deletions src/components/ui/molecules/subtask-card/SubTaskCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ interface SourceSubTask {
content_type: "SOURCE_REFERENCE";
content: string;
display_order?: number;
source_text_id?: string | null;
pecha_segment_id?: string | null;
}
export type SubTask =
| VideoSubTask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ import { Pagination } from "@/components/ui/molecules/pagination/Pagination";
import { searchSources } from "@/components/api/searchApi";
import { LANGUAGE } from "@/lib/constant";

interface SourceData {
content: string;
segment_id: string;
text_id: string;
}

interface SourceSelectorSheetProps {
isOpen: boolean;
onOpenChange: (open: boolean) => void;
onAddSource: (sourceContent: string) => void;
onAddSource: (sourceData: SourceData) => void;
}

export const SourceSelectorSheet = ({
Expand Down Expand Up @@ -55,9 +61,9 @@ export const SourceSelectorSheet = ({
};
const { t } = useTranslate();

const handleAddSource = (content: any) => {
if (content) {
onAddSource(content);
const handleAddSource = (sourceData: SourceData) => {
if (sourceData?.content) {
onAddSource(sourceData);
onOpenChange(false);
}
};
Expand Down
8 changes: 7 additions & 1 deletion src/components/ui/molecules/webuddhist-source/sourceItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ const SourceItem = ({ source, onSegment }: any) => {
<button
key={segment.segment_id || index}
className="border p-2 rounded-md text-left border-dashed border-gray-300 dark:border-[#313132] text-sm cursor-pointer"
onClick={() => onSegment?.(segment.content)}
onClick={() =>
onSegment?.({
content: segment.content,
segment_id: segment.pecha_segment_id,
text_id: source.text.text_id,
})
}
>
<div dangerouslySetInnerHTML={{ __html: segment.content }} />
</button>
Expand Down