Skip to content

Commit

Permalink
- style(job)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisGray0626 committed Jul 1, 2024
1 parent f5e028b commit 4a09b55
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
45 changes: 18 additions & 27 deletions src/store/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,32 @@ import {job2G6Tree, jobLeafNode2G6Graph} from "@/utils/graphUtil.ts";
import {computed} from "vue";
import {mockFetchJob} from "@/api/fetch.ts";
import {Task} from "@/type.ts";
// import axios from "@/api";

export const useJobStore = defineStore("job", () => {
let _job: Task;
let _job: Task;

async function fetchData(task: string) {
const res = ((await mockFetchJob(task)) as { data: any }).data;
// localData = (await axios.fetchJob(`{"task":"${task}"}`)).data;
console.debug("res", res);
_job = convertData(res);
async function fetchData(question: string) {
const res = ((await mockFetchJob(question)) as { data: any }).data;
// localData = (await axios.fetchJob(`{"question":"${question}"}`)).data;
console.debug("res", res);
_job = convertData(res);

function convertData(data: any) {
const children = data.subtasks;
const task = new Task(data.task, data.toolId, data.toolName);
function convertData(data: any) {
const children = data.subtasks;
const task = new Task(data.task, data.toolId, data.toolName);

if (children && children.length > 0) {
for (let i = 0; i < children.length; i++) {
task.addChild(convertData(children[i]));
}
}
return task;
if (children && children.length > 0) {
for (let i = 0; i < children.length; i++) {
task.addChild(convertData(children[i]));
}
}
return task;
}
}

const breakdownData = computed(() => job2G6Tree(_job));
const breakdownData = computed(() => job2G6Tree(_job));

const workflowData = computed(() => jobLeafNode2G6Graph(_job));
const workflowData = computed(() => jobLeafNode2G6Graph(_job));

const job = computed(() => {
if (!_job) {
return null;
} else {
return _job;
}
})

return {fetchData, job, breakdownData, workflowData};
return {fetchData, breakdownData, workflowData};
});
9 changes: 3 additions & 6 deletions src/store/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Session = {
};

export const useSessionStore = defineStore("session", () => {
const dataStore = useJobStore();
const jobStore = useJobStore();

const session = reactive<Session>({
sessionId: generateId(),
Expand All @@ -21,12 +21,9 @@ export const useSessionStore = defineStore("session", () => {

// TODO chatted?
async function chatted() {
if (!dataStore.job) {
await dataStore.fetchData(session.question);
}
// session.question = "";
await jobStore.fetchData(session.question);
graphShow.value = true;
}

return { session, graphShow, chatted };
return {session, graphShow, chatted};
});

0 comments on commit 4a09b55

Please sign in to comment.