-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from nteract/expanded-cell-creation
Expanded cell creation
- Loading branch information
Showing
7 changed files
with
93 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
import { useState } from 'react'; | ||
import { useState, useCallback } from 'react'; | ||
import { invoke } from "@tauri-apps/api/tauri"; | ||
|
||
type CellInfo = { | ||
id: string, | ||
cellType: "code" | "markdown" | ||
} | ||
|
||
export function useNotebook() { | ||
const [cells, setCells] = useState<string[]>([]); | ||
const [cells, setCells] = useState<CellInfo[]>([]); | ||
|
||
async function createCell() { | ||
const id = (await invoke("create_cell")) as string; | ||
setCells(oldCells => [...oldCells, id]); | ||
} | ||
const createCell = useCallback(async (cellType: "code" | "markdown") => { | ||
const id = (await invoke("create_cell", { cellType })) as string; | ||
setCells(oldCells => [...oldCells, { id, cellType }]); | ||
}, []); | ||
|
||
// TODO(kyle): Listen to events from the backend to update the cell list | ||
const createCodeCell = useCallback(() => createCell("code"), [createCell]); | ||
const createMarkdownCell = useCallback(() => createCell("markdown"), [createCell]); | ||
|
||
return { cells, createCell }; | ||
return { cells, createCell, createCodeCell, createMarkdownCell}; | ||
} |