Sorry if this has been answered before or if it is something obvious, but I couldn’t even think what to search to get the answers that I need.
I’ve been learning React on the fly for a couple of years just by building projects as and when I needed it. This means there’s a bunch of gaps in my knowledge because I’ve just learned how to do things as and when I needed it. I have an odd situation and I wanted to establish the best approach to it using react (and any other tools recommended).
I want to make a completely offline React page. The aim of this project is to essentially create a form with a bunch of text fields / select options which when submitted, will produce a Word document which is generated based on the text fields / options selected. There’s a couple of things to note:
- The documents are 2-3 pages long and contain a lot of specific
information (e.g. the user will select a client on the form,
depending on the client, there’s different data for that client
which will be inputted into the doc. - It must be completely offline. The only place this will be stored is
on a local shared network drive where a user can just open the .html file
to see the form. There’s a ton of confidentiality hurdles which means I can’t have an express server, or use any sort of online based server to handle the data.
I’ve already built out maybe 50% of it, but as I’m creating it I keep thinking that there has to be a better way to do things. These are the main questions / things I could use help with.
- I’m using the docxjs library to create the word document. I have a
base template with some images on / areas with placeholders where
text is replaced. What is the best way to ‘import’ this .docx file,
considering everything is offline and has no node backend. I tried using
fetch at first then realized this wouldn’t work because it throws
CORS errors. I don’t fully understand why if the .docx file is
stored in the public folder, but after some searching it seemed that
it isn’t possible. So I’ve resorted to converting the .docx file to
base64, then I created a function which converts that to a docxjs
supported format so I can patch the document. - I have created a sort of ‘offline database’ by just storing a bunch of data in JSON objects in separate files the code. e.g. a clientData.js file which exports an object which contains an array of objects which has info on a load of clients. Right now I just import the object I need and use it to access the info when creating the document. In the future, I may want to make it so that certain people can update this info when needed, which would mean some kind of DB would be required. Is there any sort of DB which would work completely offline to store a large amount of data to be accessed and modified? I thought of something like sqlite but would this not give me similar issues to the .docx file I mentioned earlier?
I seen some talk about utilizing a serviceworker but this isn’t something I’ve used before. So also if there’s any guidance on how this could be utilized for this project that would be great.
Thanks