Commit Graph
26 Commits
Author SHA1 Message Date
David Lechner 8ffaf64292 fileStorage: add file create option
When opening a file, sometimes we want to create it if it does not
exist and sometimes we don't.
2022-04-08 18:29:05 -05:00
David Lechner e0a6926d01 explorer: implement duplicate file feature 2022-04-08 18:11:09 -05:00
David Lechner c6cf0608f4 explorer: move files state from fileStorage
This state should be exclusivly used to for displaying files in the
explorer, so the state should be in the explorer branch of the
reducer tree.
2022-04-04 18:59:13 -05:00
David Lechner 05731e50fc explorer: split archive saga from fileStorage
This splits the fileStorage archive into two sagas to separate concerns.
fileStorage now just gives a dump of the database and explorer deals
with the user interaction and zipping.
2022-04-04 17:48:36 -05:00
David Lechner b9dbaaa5cb fileStorage: implement file locks
This breaks down reading and writing into low-level and high level sagas.

Opening now takes a lock on the file so that it can only have one writer
or have multiple readers. The low-level read and write sagas use the
file descriptor to determine if the file is still open before actually
performing the action.

Since we are using the web locks api, these locks should work across
browser tabs/windows.

The high-level read/write sagas perform the low-level open, read/write,
close operations in a single call.

The high-level delete and rename sagas are also updated to take locks
on the files while performing the respective operations and will fail
if the file is already being used somewhere else.
2022-04-04 15:24:08 -05:00
David Lechner 7ef08122e8 explorer: move export from fileStorage 2022-04-01 18:45:24 -05:00
David Lechner 1709591afc fileStorage: untangle file id/name
We were using file UUID and path interchangeable. This adds a new UUID
type for static checking and fixes a bunch of issues found.
2022-04-01 17:24:00 -05:00
David Lechner 1515e5ae4f fileStorage: add file handles
This changes how files work. There is now an open function that
translates a path to a file handle (id). Then this handle is used
to perform other actions on the file. The file contents are moved
to a separate table so that the actual file storage is independent
of the database (e.g. in the future, we may use File Access API).

We store a hash of the file contents in the metadata file so we can
detect file changes without having to compare file contents.

We also separate the change and add actions.
2022-04-01 13:41:10 -05:00
David Lechner 75c3efc5ba fileStorage: replace localforage with dexie
This gives us more fine-grained control over database transaction and
cross-tab notifications and will facilitate upgrading the database with
new metadata in the future.
2022-03-28 17:04:45 -05:00
David Lechner 3eac7d384f fileStorage/sagas: remove editor init from fileStorage
This is still a bit of a hack but is one step towards being able to
remove the 'editor' context.
2022-03-26 11:49:23 -05:00
David Lechner 549fe88a00 fileStorage/actions: fix duplicate type 2022-03-21 20:19:43 -05:00
David Lechner f9c1f7084c drop FileSaver
browser-fs-access already includes fallbacks to the file storage api
so we don't have to provide our own.
2022-03-16 14:59:10 -05:00
David Lechner 6062517dec fileStorage/sagas: use pythonFileMimeType
Missed an instance where text/x-python was hard-coded.
2022-03-16 13:22:42 -05:00
David Lechner 33974c52b3 fileStorage: add rename file actions 2022-03-12 14:18:02 -06:00
David Lechner e36a30de4c pybricksMicropython/lib: add module
This creates a new module for dealing with stuff specific to Pybricks
MicroPython.
2022-03-11 15:41:16 -06:00
David Lechner 63fc715f20 fileStorage: add didDeleteFile and didFailToDeleteFile actions
This will allow handling errors if removing a file from storage fails.
2022-03-10 13:45:10 -06:00
David Lechner fd120bb5a6 fileStorage: fix incorrect suggested file name 2022-03-10 02:10:34 -06:00
David Lechner 41fc961661 fileStorage: implement delete action 2022-03-10 01:02:18 -06:00
David Lechner 569217d5dc editor: don't put editor in redux store
The redux store should not have non-serializable objects like the editor
in it.
2022-03-02 18:56:47 -06:00
David Lechner bc7e9e2a20 fileStorage: add archive actions
This allows users to back up all files to their computer.
2022-03-02 10:33:21 -06:00
David Lechner a87e2c664c fileStorage: add export actions
These are largely copied from the editor saveAs actions and allow
exporting ("downloading") a file from the browser local storage to
the file system.
2022-03-01 13:44:08 -06:00
David Lechner 55c6841fae fileStorage/reducers: drop use of Set
Using set causes problems with tooling that mocks the global app state,
so stick with arrays.
2022-03-01 11:58:50 -06:00
David Lechner 31600c6f37 editor: fix error if main.py does not exist
The editor saga was assuming that main.py always exists, which is not
the case for the first use of the app. This fixes the issue by checking
to see if the file exists before attempting to open it. This also
revealed a bug in fileStorage where the list of files was not populated
during initialization.
2022-02-28 12:24:46 -06:00
David Lechner a9f4eaa32d actions: simplify usage of Matchable
This removes use of the pseudo-internal toString() function and also
removes extraneous uses of ReturnType<>. Also, a new when() method
is added to simplify additional uses.
2022-02-26 12:43:10 -06:00
David Lechner 9641898a75 actions: refactor actions
The pattern we were using for actions required actions to be defined in
three places, an enum member containing the type string, an type
definition and a function. This combines all three of these into one by
using a helper function based on the ideas from [1].

[1]: https://phryneas.de/redux-typescript-no-discriminating-union
2022-02-25 17:58:30 -06:00
David Lechner e4b7a9aec7 fileStorage: new file storage backend
This replaces the localStorage file storage with a new backend that uses
localForage (indexeddb) for storing the file contents. This will also
allow storing multiple files.
2022-02-24 16:59:49 -06:00