As of #35 and the initial HN thread there is an interest in providing an option to sync changes to external providers such as Google Drive, Dropbox etc.
I compiled a list of these options with a few remarks to discuss ideas and the current progress.
Dropbox:
Dropbox provides a method to create a dedicated app folder to store all the files an app needs. This way an app can't access any other personal files. Additionally the OAuth flow does not require any server side logic so the auth flow can be accomplished entirely on the client side. This way, JournalBook can store a single file, e.g. "journalbook.json" inside an user's app folder and simply overwrite it when exporting. @trys would need to create a Dropbox App and set the corresponding environment variables.
Google Drive:
The Google Javascript Client provides all methods to authenticate a user and fully interact with the Google Drive API. The most convenient way is to use the Google Picker. It's possible to limit the files shown in the picker to a certain mime type (application/json) to select a file the user wants to import/export. The selected file id is then stored locally and used to update(overwrite) the file
when the user wants to export changes. Unfortunately the picker does not provide an option to create a new empty file, so the only option is to create an empty file directly via the drive API. Therefore we might need to provide the user with an input to alter the default name of the new file ("journalbook.json"). For this to work, @trys would need to create a dedicated app in the google cloud console and supply the keys as environment variables.
GitHub:
GitHub would be an awesome addition imo. A user can log in via GitHub, choose/create a repository(private and public) and use it as storage. Changes in the local database can be serialized to json and pushed directly from the browser. GitHub does however require a server for the auth flow that stores the app's secret. That could easily be done with netlify functions since netlify is used to deploy JournalBook anyways. On the other side I don't think it is a good idea to directly couple this project with the requirement to deploy to netlify. Maybe a separate repo? Multiple options to deploy? Any ideas? Anyhow this option is not as important as the other two so it can be delayed.
All of the above can be seen more of importing and exporting rather then full blown syncing. The current import for files replaces the data in the local database. I moved the import/export methods directly into the db. This way the methods can be enhanced later without affecting the storage adapters.
The modified UI for the above options would look like this:
![bildschirmfoto 2019-01-29 um 14 39 59](https://user-images.githubusercontent.com/28021879/51912178-ed6e2100-23d3-11e9-866f-b43244c3bfa5.png)
Maybe it's a good idea to do a PR with just local file and Dropbox first, since it's already working and google drive requires a bit more work...?
Open to any ideas and feedback.