Skip to content

Commit

Permalink
detect user by filename
Browse files Browse the repository at this point in the history
  • Loading branch information
kobakazu0429 committed Nov 23, 2023
1 parent 8e7f111 commit 42e42fa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/components/Editor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
onMount(() => {
setupFullscreenEditor();
connectLanguageServer();
const close = connectLanguageServer();
willDestroyCallbacks.push(() => close());
const { code, filename } = recoveryCode();
monacoEditorCode.update(() => code);
Expand Down
1 change: 1 addition & 0 deletions src/editor/lsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const connectLanguageServer = () => {
languageClient.start();
reader.onClose(async () => await languageClient.stop());
};
return () => webSocket.close();
};

const createLanguageClient = (transports: MessageTransports): MonacoLanguageClient => {
Expand Down
7 changes: 4 additions & 3 deletions src/editor/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ulid } from "ulid";
import { decompressLzString } from "../compression";
import { editor, lz as lzStore, monacoEditorCode } from "../store";
import { redToast } from "../toast";
import { clearCode, getPreviousCode } from "./../localStorage/index";
import { clearCode, getPreviousCode, getUser } from "./../localStorage/index";
import { resetUrl } from "../url";
import type { Test } from "../test";

Expand Down Expand Up @@ -67,19 +67,20 @@ export interface RecoveryCode {
tests?: Test[];
}
export const recoveryCode = (): RecoveryCode => {
const user = getUser();
const lz = get(lzStore);
if (lz) {
const decompressedLz = decompressLzString(lz);
if (decompressedLz !== "") {
const recovered = JSON.parse(decompressedLz) as Partial<RecoveryCode>;
recovered.code = recovered.code ? recovered.code.replaceAll(/\r(\r)+/g, "\r") : "";
recovered.filename ??= `${ulid()}.c`;
recovered.filename ??= `${user.id}-${ulid()}.c`;
return recovered as RecoveryCode;
}
}
const previousCode = getPreviousCode();
const code = previousCode?.code ?? "";
const filename = previousCode?.filename ?? `${ulid()}.c`;
const filename = previousCode?.filename ?? `${user.id}-${ulid()}.c`;
const tests = previousCode?.tests;
return { code, filename, tests };
};
Expand Down

0 comments on commit 42e42fa

Please sign in to comment.