Add example document from Rust code
This commit is contained in:
parent
ff9069eda5
commit
2e2fb39c33
4 changed files with 58 additions and 3 deletions
22
package-lock.json
generated
22
package-lock.json
generated
|
@ -23,6 +23,7 @@
|
|||
"@types/react-dom": "^17.0.5",
|
||||
"monaco-editor": "^0.23.0",
|
||||
"prettier": "2.3.0",
|
||||
"raw.macro": "^0.4.2",
|
||||
"react-app-rewired": "^2.1.8",
|
||||
"typescript": "^4.3.2",
|
||||
"wasm-loader": "^1.3.0"
|
||||
|
@ -16844,6 +16845,18 @@
|
|||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/raw.macro": {
|
||||
"version": "0.4.2",
|
||||
"resolved": "https://registry.npmjs.org/raw.macro/-/raw.macro-0.4.2.tgz",
|
||||
"integrity": "sha512-Z+zKtCweyJ3lGYdUNq/BQwfzqQE2wrXjz0RNEes5nDniPpjvBw64sKYFXStJSfmZUmiBxv4DsN1lto982UAhFQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"babel-plugin-macros": "^2.8.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/react": {
|
||||
"version": "17.0.2",
|
||||
"resolved": "https://registry.npmjs.org/react/-/react-17.0.2.tgz",
|
||||
|
@ -35738,6 +35751,15 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"raw.macro": {
|
||||
"version": "0.4.2",
|
||||
"resolved": "https://registry.npmjs.org/raw.macro/-/raw.macro-0.4.2.tgz",
|
||||
"integrity": "sha512-Z+zKtCweyJ3lGYdUNq/BQwfzqQE2wrXjz0RNEes5nDniPpjvBw64sKYFXStJSfmZUmiBxv4DsN1lto982UAhFQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"babel-plugin-macros": "^2.8.0"
|
||||
}
|
||||
},
|
||||
"react": {
|
||||
"version": "17.0.2",
|
||||
"resolved": "https://registry.npmjs.org/react/-/react-17.0.2.tgz",
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
"@types/react-dom": "^17.0.5",
|
||||
"monaco-editor": "^0.23.0",
|
||||
"prettier": "2.3.0",
|
||||
"raw.macro": "^0.4.2",
|
||||
"react-app-rewired": "^2.1.8",
|
||||
"typescript": "^4.3.2",
|
||||
"wasm-loader": "^1.3.0"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//! Asynchronous systems logic for Rustpad.
|
||||
//! Eventually consistent server-side logic for Rustpad.
|
||||
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::time::Duration;
|
||||
|
@ -13,7 +13,7 @@ use tokio::sync::{broadcast, Notify};
|
|||
use tokio::time;
|
||||
use warp::ws::{Message, WebSocket};
|
||||
|
||||
/// The main object for a collaborative session.
|
||||
/// The main object representing a collaborative session.
|
||||
pub struct Rustpad {
|
||||
/// State modified by critical sections of the code.
|
||||
state: RwLock<State>,
|
||||
|
@ -74,7 +74,7 @@ impl From<ServerMsg> for Message {
|
|||
|
||||
impl Default for Rustpad {
|
||||
fn default() -> Self {
|
||||
let (tx, _) = broadcast::channel(1);
|
||||
let (tx, _) = broadcast::channel(16);
|
||||
Self {
|
||||
state: Default::default(),
|
||||
count: Default::default(),
|
||||
|
|
32
src/App.tsx
32
src/App.tsx
|
@ -27,6 +27,7 @@ import {
|
|||
} from "react-icons/vsc";
|
||||
import Editor from "@monaco-editor/react";
|
||||
import { editor } from "monaco-editor/esm/vs/editor/editor.api";
|
||||
import raw from "raw.macro";
|
||||
import Rustpad from "./rustpad";
|
||||
import languages from "./languages.json";
|
||||
|
||||
|
@ -114,6 +115,26 @@ function App() {
|
|||
});
|
||||
}
|
||||
|
||||
function handleLoadSample() {
|
||||
if (editor) {
|
||||
const model = editor.getModel()!;
|
||||
model.pushEditOperations(
|
||||
editor.getSelections(),
|
||||
[
|
||||
{
|
||||
range: model.getFullModelRange(),
|
||||
text: raw("../rustpad-server/src/rustpad.rs"),
|
||||
},
|
||||
],
|
||||
() => null
|
||||
);
|
||||
editor.setPosition({ column: 0, lineNumber: 0 });
|
||||
if (language !== "rust") {
|
||||
handleChangeLanguage("rust");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Flex direction="column" h="100vh" overflow="hidden">
|
||||
<Box
|
||||
|
@ -211,6 +232,7 @@ function App() {
|
|||
Built using Rust and TypeScript. See the{" "}
|
||||
<Link
|
||||
color="blue.600"
|
||||
fontWeight="semibold"
|
||||
href="https://github.com/ekzhang/rustpad"
|
||||
isExternal
|
||||
>
|
||||
|
@ -218,6 +240,16 @@ function App() {
|
|||
</Link>{" "}
|
||||
for details.
|
||||
</Text>
|
||||
|
||||
<Button
|
||||
size="sm"
|
||||
colorScheme="purple"
|
||||
variant="outline"
|
||||
mt={2}
|
||||
onClick={handleLoadSample}
|
||||
>
|
||||
Read the code
|
||||
</Button>
|
||||
</Container>
|
||||
</Flex>
|
||||
<Flex flex={1} minW={0} h="100%" direction="column" overflow="hidden">
|
||||
|
|
Loading…
Add table
Reference in a new issue