Skip to content

Commit

Permalink
Bug Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
R1c4rdCo5t4 committed Jun 6, 2024
1 parent 3b68f31 commit 515e509
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 30 deletions.
2 changes: 1 addition & 1 deletion code/client/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const SERVER_URL = 'https://notespace-0es7.onrender.com';
const SERVER_URL = 'http://localhost:8080';

export default {
SERVER_URL,
Expand Down
12 changes: 4 additions & 8 deletions code/client/src/domain/editor/fugue/Fugue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,18 @@ export class Fugue {
*/
private getInsertOperation({ line, column }: Cursor, { value, styles }: NodeInsert) {
const id = { sender: this.replicaId, counter: this.counter++ };

const leftOrigin = this.getNodeByCursor({ line, column })!;

const parent = (
isEmpty(leftOrigin.rightChildren) ? leftOrigin : this.tree.getLeftmostDescendant(leftOrigin.rightChildren[0])
).id;
const operation: InsertOperation = {
type: 'insert',
id,
value,
parent: (isEmpty(leftOrigin.rightChildren)
? leftOrigin
: this.tree.getLeftmostDescendant(leftOrigin.rightChildren[0])
).id,
parent,
side: isEmpty(leftOrigin.rightChildren) ? 'R' : 'L',
styles,
};

if (value === '\n') operation.line = line;
return operation;
}
Expand Down Expand Up @@ -334,7 +331,6 @@ export class Fugue {
*/
getNodeByCursor({ line, column }: Cursor): FugueNode | undefined {
if (column === 0) return this.tree.getLineRoot(line);

const start = { line, column: column - 1 };
const end = { line, column };
const iterator = this.traverseBySelection({ start, end });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ export default (fugue: Fugue, { socket }: Communication): InputDomainOperations
}

function insertLineBreak(cursor: Cursor) {
const operations = fugue.insertLocal(cursor, '\n');
const styleOperation = fugue.updateBlockStyleLocal(cursor.line + 1, 'paragraph', true);
socket.emit('operations', [styleOperation, ...operations]);
const operations: Operation[] = fugue.insertLocal(cursor, '\n');
const style = cursor.column === 0 ? fugue.getBlockStyle(cursor.line) : 'paragraph'; // inherit block style when inserting line break at the beginning of a line
if (cursor.column === 0) {
const styleOperation = fugue.updateBlockStyleLocal(cursor.line + 1, style, true);
operations.push(styleOperation);
}
socket.emit('operations', operations);
}

function deleteCharacter(cursor: Cursor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,24 @@ export default (editor: Editor, handlers: MarkdownDomainOperations) => {
});
const path = block ? block[1] : [];
const end = editor.end(path);
Transforms.splitNodes(editor, { always: true });

const element = block![0] as Element;

const type = element.type as BlockStyle;
if (!isMultiBlock(type)) {
Transforms.setNodes(editor, { type: 'paragraph' });
CustomEditor.resetMarks(editor);

// Check if the selection is at the start of the block
if (Point.equals(selection.anchor, editor.start(path))) {
// If it is, create a new block of the same type above the current block
Transforms.insertNodes(editor, { type, children: [{ text: '' }] }, { at: path });
} else {
const { start } = getSelection(editor);
handlers.applyBlockStyle(type, start.line);
// If it's not, split the block as usual
Transforms.splitNodes(editor, { always: true });

if (!isMultiBlock(type)) {
Transforms.setNodes(editor, { type: 'paragraph' });
CustomEditor.resetMarks(editor);
} else {
const { start } = getSelection(editor);
handlers.applyBlockStyle(type, start.line);
}
}
// if selection was at the end of the block, unwrap the block
if (!Point.equals(end, Range.end(selection))) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ type CreateResourceMenuProps = {
function CreateResourceMenu({ onCreateNew, trigger }: CreateResourceMenuProps) {
return (
<PopupMenu item={<></>} trigger={trigger}>
<button onClick={() => onCreateNew(ResourceType.FOLDER)}>
<MdCreateNewFolder />
Folder
</button>
<button onClick={() => onCreateNew(ResourceType.DOCUMENT)}>
<BsFileEarmarkPlusFill />
Document
</button>
<button onClick={() => onCreateNew(ResourceType.FOLDER)}>
<MdCreateNewFolder />
Folder
</button>
</PopupMenu>
);
}
Expand Down
2 changes: 1 addition & 1 deletion code/client/src/ui/pages/document/Document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function Document() {
const navigate = useNavigate();

useEffect(() => {
setLoaded(false); // reset state to load new document (useful for when navigating between documents)
setLoaded(false); // reset state to load new document (for when navigating between documents)

async function fetchDocument() {
if (!id) return;
Expand Down
2 changes: 1 addition & 1 deletion code/client/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ export function formatTimePassed(isoString: string): string {
} else if (minutes > 0) {
return formatTime(minutes, 'minute');
} else {
return seconds === 0 ? 'Just now' : formatTime(seconds, 'second');
return seconds <= 0 ? 'Just now' : formatTime(seconds, 'second');
}
}
4 changes: 1 addition & 3 deletions code/server/src/databases/memory/MemoryResourcesDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ export class MemoryResourcesDB implements ResourcesRepository {

async updateResource(id: string, newProps: Partial<Resource>) {
const resource = this.getResourceById(id);
Object.assign(resource, newProps);

if (newProps.parent) {
const prevParent = this.getResourceById(resource.parent);
prevParent.children = prevParent.children.filter((childId: string) => childId !== id);
const newParent = this.getResourceById(newProps.parent);
newParent.children.push(id);
}
Object.assign(resource, newProps);
}

async deleteResource(id: string) {
Expand All @@ -64,7 +63,6 @@ export class MemoryResourcesDB implements ResourcesRepository {

// delete resource
delete Memory.workspaces[resource.workspace].resources[id];
console.log(Memory.workspaces[resource.workspace].resources[id]);
}

private getResourceById(id: string) {
Expand Down
1 change: 0 additions & 1 deletion code/server/test/workspaces/tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ describe('Workspace tree operations', () => {
await services.resources.createResource(wid, 'doc2', ResourceType.DOCUMENT, docId);
await services.resources.deleteResource(folderId);
const resources = excludeRoot(wid, await services.workspaces.getResources(wid));
console.log(resources);
expect(resources.length).toBe(0);
});
});

0 comments on commit 515e509

Please sign in to comment.