🚚(frontend) move toBase64

We will need toBase64 in different features,
better to move it to "doc-management".
This commit is contained in:
Anthony LC
2025-02-13 16:56:38 +01:00
parent 971b7e099d
commit f27e968c15
3 changed files with 4 additions and 6 deletions

View File

@@ -2,12 +2,10 @@ import { useRouter } from 'next/router';
import { useCallback, useEffect, useRef, useState } from 'react';
import * as Y from 'yjs';
import { useUpdateDoc } from '@/features/docs/doc-management/';
import { toBase64, useUpdateDoc } from '@/features/docs/doc-management/';
import { KEY_LIST_DOC_VERSIONS } from '@/features/docs/doc-versioning';
import { isFirefox } from '@/utils/userAgent';
import { toBase64 } from '../utils';
const useSaveDoc = (docId: string, doc: Y.Doc, canSave: boolean) => {
const { mutate: updateDoc } = useUpdateDoc({
listInvalideQueries: [KEY_LIST_DOC_VERSIONS],

View File

@@ -22,6 +22,3 @@ function hslToHex(h: number, s: number, l: number) {
};
return `#${f(0)}${f(8)}${f(4)}`;
}
export const toBase64 = (str: Uint8Array) =>
Buffer.from(str).toString('base64');

View File

@@ -12,6 +12,9 @@ export const currentDocRole = (abilities: Doc['abilities']): Role => {
: Role.READER;
};
export const toBase64 = (str: Uint8Array) =>
Buffer.from(str).toString('base64');
export const base64ToYDoc = (base64: string) => {
const uint8Array = Buffer.from(base64, 'base64');
const ydoc = new Y.Doc();