mirror of
https://github.com/outline/outline.git
synced 2026-12-02 01:34:47 +03:00
iteration
This commit is contained in:
1 parent
ce65f27a47
commit
79b92b92aa
6 files changed
+67
-33
No files matched your search
@@ -0,0 +1,9 @@
|
||||
// @flow
|
||||
import invariant from "invariant";
|
||||
import useStores from "./useStores";
|
||||
|
||||
export default function useCurrentToken() {
|
||||
const { auth } = useStores();
|
||||
invariant(auth.token, "token is required");
|
||||
return auth.token;
|
||||
}
|
||||
@@ -262,7 +262,7 @@ export default class Document extends BaseModel {
|
||||
};
|
||||
|
||||
@action
|
||||
update = async (options: SaveOptions & { title: string }) => {
|
||||
update = async (options: {| ...SaveOptions, title: string |}) => {
|
||||
if (this.isSaving) return this;
|
||||
this.isSaving = true;
|
||||
|
||||
@@ -283,7 +283,7 @@ export default class Document extends BaseModel {
|
||||
};
|
||||
|
||||
@action
|
||||
save = async (options: SaveOptions = {}) => {
|
||||
save = async (options: ?SaveOptions = {}) => {
|
||||
if (this.isSaving) return this;
|
||||
|
||||
const isCreating = !this.id;
|
||||
|
||||
@@ -8,6 +8,7 @@ class User extends BaseModel {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
color: string;
|
||||
isAdmin: boolean;
|
||||
isViewer: boolean;
|
||||
lastActiveAt: string;
|
||||
|
||||
@@ -16,6 +16,7 @@ export default class MultiplayerExtension extends Extension {
|
||||
}
|
||||
|
||||
get plugins() {
|
||||
console.log(this.options);
|
||||
const { user, provider, document: doc } = this.options;
|
||||
const type = doc.get("prosemirror", Y.XmlFragment);
|
||||
|
||||
|
||||
@@ -4,34 +4,58 @@ import * as React from "react";
|
||||
import * as Y from "yjs";
|
||||
import Editor from "components/Editor";
|
||||
import env from "env";
|
||||
import useCurrentToken from "hooks/useCurrentToken";
|
||||
import useCurrentUser from "hooks/useCurrentUser";
|
||||
import MultiplayerExtension from "multiplayer/MultiplayerExtension";
|
||||
|
||||
const style = { position: "absolute", width: "100%" };
|
||||
|
||||
// TODO: typing
|
||||
export default function MultiplayerEditor(props: any) {
|
||||
const user = useCurrentUser();
|
||||
function MultiplayerEditor(props: any, ref) {
|
||||
const currentUser = useCurrentUser();
|
||||
const token = useCurrentToken();
|
||||
const [showCachedDocument, setShowCachedDocument] = React.useState(true);
|
||||
const [isRemoteSynced, setRemoteSynced] = React.useState(true);
|
||||
|
||||
// TODO
|
||||
//const [showCachedDocument, setShowCachedDocument] = React.useState(true);
|
||||
React.useEffect(() => {
|
||||
console.log("mount");
|
||||
}, []);
|
||||
|
||||
// React.useEffect(() => {
|
||||
// if (isRemoteSynced) {
|
||||
// setTimeout(() => setShowCachedDocument(false), 100);
|
||||
// }
|
||||
// }, [showCachedDocument, isRemoteSynced]);
|
||||
React.useEffect(() => {
|
||||
if (isRemoteSynced) {
|
||||
setTimeout(() => setShowCachedDocument(false), 100);
|
||||
}
|
||||
}, [isRemoteSynced]);
|
||||
|
||||
const user = React.useMemo(() => {
|
||||
return {
|
||||
id: currentUser.id,
|
||||
name: currentUser.name,
|
||||
color: currentUser.color,
|
||||
};
|
||||
}, [currentUser.id, currentUser.color, currentUser.name]);
|
||||
|
||||
const extensions = React.useMemo(() => {
|
||||
console.log("extensions");
|
||||
|
||||
const ydoc = new Y.Doc();
|
||||
console.log("new HocuspocusProvider", ydoc);
|
||||
|
||||
const provider = new HocuspocusProvider({
|
||||
url: env.MULTIPLAYER_URL,
|
||||
|
||||
// TODO: pipe documentId
|
||||
name: "example-document",
|
||||
debug: env.ENVIRONMENT === "development",
|
||||
name: `document.${props.id}`,
|
||||
document: ydoc,
|
||||
parameters: {
|
||||
token,
|
||||
},
|
||||
});
|
||||
|
||||
const handleSynced = () => {
|
||||
setRemoteSynced(true);
|
||||
provider.off("sync", handleSynced);
|
||||
};
|
||||
|
||||
provider.on("sync", handleSynced);
|
||||
|
||||
return [
|
||||
new MultiplayerExtension({
|
||||
user,
|
||||
@@ -39,27 +63,25 @@ export default function MultiplayerEditor(props: any) {
|
||||
document: ydoc,
|
||||
}),
|
||||
];
|
||||
}, [user]);
|
||||
}, [user, token, props.id]);
|
||||
|
||||
return (
|
||||
<span style={{ position: "relative" }}>
|
||||
{true && (
|
||||
{isRemoteSynced && (
|
||||
<Editor
|
||||
{...props}
|
||||
key="multiplayer"
|
||||
defaultValue={undefined}
|
||||
value={undefined}
|
||||
extensions={extensions}
|
||||
style={{ position: "absolute", width: "100%" }}
|
||||
style={style}
|
||||
ref={ref}
|
||||
/>
|
||||
)}
|
||||
{/* {showCachedDocument && (
|
||||
<Editor
|
||||
{...props}
|
||||
style={{ position: "absolute", width: "100%" }}
|
||||
readOnly
|
||||
/>
|
||||
)} */}
|
||||
{/* {showCachedDocument && <Editor {...props} style={style} readOnly />} */}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
export default React.forwardRef<any, typeof MultiplayerEditor>(
|
||||
MultiplayerEditor
|
||||
);
|
||||
@@ -4,14 +4,13 @@ import { Server } from "@hocuspocus/server";
|
||||
import debug from "debug";
|
||||
//import { RocksDB } from "@hocuspocus/extension-rocksdb";
|
||||
import { AuthenticationError } from "../errors";
|
||||
//import policy from "../policies";
|
||||
import { Document } from "../models";
|
||||
import policy from "../policies";
|
||||
import { getUserForJWT } from "../utils/jwt";
|
||||
|
||||
const isProduction = process.env.NODE_ENV === "production";
|
||||
const log = debug("multiplayer");
|
||||
//const { can } = policy;
|
||||
const can = () => true;
|
||||
// const isProduction = process.env.NODE_ENV === "production";
|
||||
// const log = debug("multiplayer");
|
||||
const { can } = policy;
|
||||
|
||||
const server = Server.configure({
|
||||
port: process.env.MULTIPLAYER_PORT || process.env.PORT || 80,
|
||||
@@ -21,7 +20,9 @@ const server = Server.configure({
|
||||
|
||||
// allows for different entity types to use this multiplayer provider later
|
||||
const [, documentId] = documentName.split(".");
|
||||
const { token } = requestParameters;
|
||||
|
||||
// TODO: https://github.com/ueberdosis/hocuspocus/issues/145
|
||||
const token = requestParameters.get("token");
|
||||
|
||||
if (!token) {
|
||||
throw new AuthenticationError("Authentication required");
|
||||
|
||||
Reference in new issue
Block a user