0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-01 21:42:44 +00:00

Initial test

This commit is contained in:
Trevor Buckner
2025-06-27 08:07:02 -04:00
parent 7bdeeee9ef
commit e1e661976d
5 changed files with 45 additions and 4 deletions

View File

@@ -3,6 +3,7 @@ require('./editPage.less');
const React = require('react');
const _ = require('lodash');
const createClass = require('create-react-class');
import {makePatches, applyPatches, stringifyPatches, parsePatches} from '@sanity/diff-match-patch';
import request from '../../utils/request-middleware.js';
const { Meta } = require('vitreum/headtags');
@@ -251,9 +252,30 @@ const EditPage = createClass({
const transfer = this.state.saveGoogle == _.isNil(this.state.brew.googleId);
const brew = this.state.brew;
const brew = { ...this.state.brew };
let jsonString = JSON.stringify(brew);
let bytes = new TextEncoder().encode(jsonString).length;
console.log(`Before size: ${bytes} bytes (${(bytes / 1024).toFixed(2)} KB)`);
brew.pageCount = ((brew.renderer=='legacy' ? brew.text.match(/\\page/g) : brew.text.match(/^\\page$/gm)) || []).length + 1;
brew.patches = makePatches(this.savedBrew.text, brew.text);
brew.text = undefined;
brew.textBin = undefined;
console.log('Saving Brew', brew);
jsonString = JSON.stringify(brew);
bytes = new TextEncoder().encode(jsonString).length;
console.log(`After size: ${bytes} bytes (${(bytes / 1024).toFixed(2)} KB)`);
jsonString = JSON.stringify(brew.patches);
bytes = new TextEncoder().encode(jsonString).length;
console.log(`Patch size: ${bytes} bytes (${(bytes / 1024).toFixed(2)} KB)`);
const params = `${transfer ? `?${this.state.saveGoogle ? 'saveToGoogle' : 'removeFromGoogle'}=true` : ''}`;
const res = await request
.put(`/api/update/${brew.editId}${params}`)