| 25 | }>; |
| 26 | |
| 27 | export class AiFileDiffViewModel implements ViewModel { |
| 28 | blockId: string; |
| 29 | nodeModel: BlockNodeModel; |
| 30 | tabModel: TabModel; |
| 31 | env: AiFileDiffEnv; |
| 32 | viewType = "aifilediff"; |
| 33 | blockAtom: jotai.Atom<Block>; |
| 34 | diffDataAtom: jotai.PrimitiveAtom<DiffData | null>; |
| 35 | errorAtom: jotai.PrimitiveAtom<string | null>; |
| 36 | loadingAtom: jotai.PrimitiveAtom<boolean>; |
| 37 | viewIcon: jotai.Atom<string>; |
| 38 | viewName: jotai.Atom<string>; |
| 39 | viewText: jotai.Atom<string>; |
| 40 | |
| 41 | constructor({ blockId, nodeModel, tabModel, waveEnv }: ViewModelInitType) { |
| 42 | this.blockId = blockId; |
| 43 | this.nodeModel = nodeModel; |
| 44 | this.tabModel = tabModel; |
| 45 | this.env = waveEnv as AiFileDiffEnv; |
| 46 | this.blockAtom = this.env.wos.getWaveObjectAtom<Block>(`block:${blockId}`); |
| 47 | this.diffDataAtom = jotai.atom(null) as jotai.PrimitiveAtom<DiffData | null>; |
| 48 | this.errorAtom = jotai.atom(null) as jotai.PrimitiveAtom<string | null>; |
| 49 | this.loadingAtom = jotai.atom<boolean>(true); |
| 50 | this.viewIcon = jotai.atom("file-lines"); |
| 51 | this.viewName = jotai.atom("AI Diff Viewer"); |
| 52 | this.viewText = jotai.atom((get) => { |
| 53 | const diffData = get(this.diffDataAtom); |
| 54 | return diffData?.fileName ?? ""; |
| 55 | }); |
| 56 | } |
| 57 | |
| 58 | get viewComponent(): ViewComponent { |
| 59 | return AiFileDiffView; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | function AiFileDiffView({ blockId, model }: ViewComponentProps<AiFileDiffViewModel>) { |
| 64 | const blockData = jotai.useAtomValue(model.blockAtom); |
nothing calls this directly
no outgoing calls
no test coverage detected