Repository navigation
Expand file tree
/
Copy pathDraftThreadHeader.tsx
More file actions
95 lines (94 loc) · 3.53 KB
/
Copy pathDraftThreadHeader.tsx
File metadata and controls
95 lines (94 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { uuidv4 } from "../../lib/uuid";
import * as Dialog from "../../components/ui/Dialog";
import { useNavigation } from "@react-navigation/native";
import { AsyncResult } from "effect/reactivity";
import * as Cause from "effect/Cause";
import { AuthFilesystemReadScope, AuthSourceControlWriteScope } from "@t3tools/contracts";
import type {
EnvironmentProject,
EnvironmentThreadShell,
} from "@t3tools/client-runtime/state/shell";
import { useEnvironmentQuery } from "../../state/query";
import { useEnvironmentScope } from "../../state/session";
import { useAtomCommand } from "../../state/use-atom-command";
import { vcsActionManager, vcsEnvironment } from "../../state/vcs";
import { useVcsActionState } from "../../state/use-vcs-action-state";
import { ThreadHeader } from "./ThreadHeader";
export function DraftThreadHeader(props: {
readonly thread: EnvironmentThreadShell;
readonly project: EnvironmentProject;
readonly cwd: string | null;
}) {
const navigation = useNavigation();
const environmentId = props.thread.environmentId;
const canReadFiles = useEnvironmentScope(environmentId, AuthFilesystemReadScope);
const canWriteGit = useEnvironmentScope(environmentId, AuthSourceControlWriteScope);
const status = useEnvironmentQuery(
props.cwd ? vcsEnvironment.status({ environmentId, input: { cwd: props.cwd } }) : null,
);
const target = { environmentId, cwd: props.cwd };
const progress = useVcsActionState(target);
const runAction = useAtomCommand(vcsActionManager.runStackedAction(target), {
reportFailure: false,
});
const pull = useAtomCommand(vcsEnvironment.pull, { reportFailure: false });
const openFiles = () => {
if (!props.cwd || !canReadFiles) return;
navigation.navigate("NewTaskFiles", {
environmentId,
cwd: props.cwd,
projectName: props.project.title,
});
};
const requiresThread = () =>
Dialog.alert("Available after the first message", "This action needs a saved thread.");
return (
<ThreadHeader
draft
title="New thread"
subtitle=""
hasThreadCwd={props.cwd !== null}
inspectorMode={null}
onOpenFilesInspector={openFiles}
gitControls={{
environmentId,
threadId: props.thread.id,
hasThread: false,
currentBranch: props.thread.branch,
gitStatus: status.data,
gitOperationLabel: progress.currentLabel,
canOpenTerminal: false,
canOperateTerminal: false,
canOpenFiles: canReadFiles && props.cwd !== null,
projectScripts: [],
terminalSessions: [],
onOpenFilesInspector: openFiles,
onOpenGitInspector: requiresThread,
onOpenTerminal: requiresThread,
onOpenNewTerminal: requiresThread,
onRunProjectScript: async () => {
requiresThread();
},
onPull: async () => {
if (!canWriteGit || !props.cwd) return;
const result = await pull({ environmentId, input: { cwd: props.cwd } });
if (AsyncResult.isFailure(result))
Dialog.alert("Could not pull", String(Cause.squash(result.cause)));
},
onRunAction: async (input) => {
if (!canWriteGit || !props.cwd) return null;
const result = await runAction({
...input,
projectId: props.project.id,
actionId: uuidv4(),
});
if (AsyncResult.isFailure(result)) {
Dialog.alert("Git action failed", String(Cause.squash(result.cause)));
return null;
}
return result.value;
},
}}
/>
);
}