Browse Source

More frontend UI updates

Eric Zhang 4 years ago
parent
commit
94b97c4767
2 changed files with 116 additions and 24 deletions
  1. 58 24
      src/App.tsx
  2. 58 0
      src/languages.json

+ 58 - 24
src/App.tsx

@@ -1,21 +1,26 @@
-import { useEffect } from "react";
+import { useEffect, useState } from "react";
 import { set_panic_hook } from "rustpad-wasm";
 import { set_panic_hook } from "rustpad-wasm";
 import {
 import {
   Box,
   Box,
+  Button,
   Container,
   Container,
   Flex,
   Flex,
   Heading,
   Heading,
   HStack,
   HStack,
   Icon,
   Icon,
   Input,
   Input,
+  InputGroup,
+  InputRightElement,
   Link,
   Link,
   Select,
   Select,
   Stack,
   Stack,
   Text,
   Text,
+  useToast,
 } from "@chakra-ui/react";
 } from "@chakra-ui/react";
 import { VscAccount, VscRemote } from "react-icons/vsc";
 import { VscAccount, VscRemote } from "react-icons/vsc";
 import Editor from "@monaco-editor/react";
 import Editor from "@monaco-editor/react";
 import Rustpad from "./rustpad";
 import Rustpad from "./rustpad";
+import languages from "./languages.json";
 
 
 set_panic_hook();
 set_panic_hook();
 
 
@@ -25,15 +30,30 @@ const WS_URI =
   "/api/socket";
   "/api/socket";
 
 
 function App() {
 function App() {
+  const toast = useToast();
+  const [language, setLanguage] = useState("plaintext");
+  const [connected, setConnected] = useState(false);
+
   useEffect(() => {
   useEffect(() => {
     const rustpad = new Rustpad({
     const rustpad = new Rustpad({
       uri: WS_URI,
       uri: WS_URI,
-      onConnected: () => console.log("connected!"),
-      onDisconnected: () => console.log("disconnected!"),
+      onConnected: () => setConnected(true),
+      onDisconnected: () => setConnected(false),
     });
     });
     return () => rustpad.dispose();
     return () => rustpad.dispose();
   }, []);
   }, []);
 
 
+  async function handleCopy() {
+    await navigator.clipboard.writeText(`${window.location.origin}/`);
+    toast({
+      title: "Copied!",
+      description: "Link copied to clipboard",
+      status: "success",
+      duration: 2000,
+      isClosable: true,
+    });
+  }
+
   return (
   return (
     <Flex direction="column" h="100vh" overflow="hidden">
     <Flex direction="column" h="100vh" overflow="hidden">
       <Box
       <Box
@@ -48,23 +68,44 @@ function App() {
       </Box>
       </Box>
       <Flex flex="1 0" minH={0}>
       <Flex flex="1 0" minH={0}>
         <Flex direction="column" bgColor="#f3f3f3" w="sm" overflowY="auto">
         <Flex direction="column" bgColor="#f3f3f3" w="sm" overflowY="auto">
-          <Container maxW="full" lineHeight={1.4}>
+          <Container maxW="full" lineHeight={1.4} py={4}>
+            <Text fontSize="sm" fontStyle="italic" color="gray.600">
+              {connected ? "You are connected!" : "Connecting to the server..."}
+            </Text>
+
             <Heading mt={4} mb={1.5} size="sm">
             <Heading mt={4} mb={1.5} size="sm">
-              Share Link
+              Language
             </Heading>
             </Heading>
-            <Input
-              readOnly
+            <Select
               size="sm"
               size="sm"
-              variant="outline"
-              value={`${window.location.origin}/`}
-            />
+              bgColor="white"
+              value={language}
+              onChange={(event) => setLanguage(event.target.value)}
+            >
+              {languages.map((lang) => (
+                <option key={lang} value={lang}>
+                  {lang}
+                </option>
+              ))}
+            </Select>
 
 
             <Heading mt={4} mb={1.5} size="sm">
             <Heading mt={4} mb={1.5} size="sm">
-              Language
+              Share Link
             </Heading>
             </Heading>
-            <Select size="sm">
-              <option value="text">Text</option>
-            </Select>
+            <InputGroup size="sm">
+              <Input
+                readOnly
+                pr="3.5rem"
+                variant="outline"
+                bgColor="white"
+                value={`${window.location.origin}/`}
+              />
+              <InputRightElement width="3.5rem">
+                <Button h="1.4rem" size="xs" onClick={handleCopy}>
+                  Copy
+                </Button>
+              </InputRightElement>
+            </InputGroup>
 
 
             <Heading mt={4} mb={1.5} size="sm">
             <Heading mt={4} mb={1.5} size="sm">
               Active Users
               Active Users
@@ -85,8 +126,8 @@ function App() {
               editor based on the <em>operational transformation</em> algorithm.
               editor based on the <em>operational transformation</em> algorithm.
             </Text>
             </Text>
             <Text fontSize="sm" mb={1.5}>
             <Text fontSize="sm" mb={1.5}>
-              Share a link to this pad with others, and they can edit it from
-              their browser while seeing your changes in real time.
+              Share a link to this pad with others, and they can edit from their
+              browser while seeing your changes in real time.
             </Text>
             </Text>
             <Text fontSize="sm" mb={1.5}>
             <Text fontSize="sm" mb={1.5}>
               Built using Rust and TypeScript. See the{" "}
               Built using Rust and TypeScript. See the{" "}
@@ -103,17 +144,10 @@ function App() {
         </Flex>
         </Flex>
         <Editor
         <Editor
           theme="vs"
           theme="vs"
+          language={language}
           options={{
           options={{
             automaticLayout: true,
             automaticLayout: true,
             fontSize: 14,
             fontSize: 14,
-            quickSuggestions: false,
-            parameterHints: {
-              enabled: false,
-            },
-            suggestOnTriggerCharacters: false,
-            acceptSuggestionOnEnter: "off",
-            tabCompletion: "off",
-            wordBasedSuggestions: false,
           }}
           }}
         />
         />
       </Flex>
       </Flex>

+ 58 - 0
src/languages.json

@@ -0,0 +1,58 @@
+[
+  "apex",
+  "azcli",
+  "bat",
+  "c",
+  "clojure",
+  "coffeescript",
+  "cpp",
+  "csharp",
+  "csp",
+  "css",
+  "dockerfile",
+  "fsharp",
+  "go",
+  "graphql",
+  "handlebars",
+  "html",
+  "ini",
+  "java",
+  "javascript",
+  "json",
+  "kotlin",
+  "less",
+  "lua",
+  "markdown",
+  "msdax",
+  "mysql",
+  "objective-c",
+  "pascal",
+  "perl",
+  "pgsql",
+  "php",
+  "plaintext",
+  "postiats",
+  "powerquery",
+  "powershell",
+  "pug",
+  "python",
+  "r",
+  "razor",
+  "redis",
+  "redshift",
+  "ruby",
+  "rust",
+  "sb",
+  "scheme",
+  "scss",
+  "shell",
+  "sol",
+  "sql",
+  "st",
+  "swift",
+  "tcl",
+  "typescript",
+  "vb",
+  "xml",
+  "yaml"
+]