joshwcomeau/guppy

Alert users when a project can't be read

开放

#184 创建于 2018年8月31日

 (10 条评论) (0 个反应) (0 位负责人)JavaScript (151 个派生)github user discovery
good first issue

仓库指标

星标
 (3,240 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

Summary When a project is deleted from disk, it will be silently removed from Guppy.

In many cases, this behaviour is fine; if the user deletes it with Finder/Explorer, it should naturally also disappear from Guppy. But given that this app is targeted at beginners, it might be good to throw a notice prompt up:

Project deleted

Your projects Thing 1, Thing 2, and Thing 3 were deleted from disk, and have been removed from Guppy.

Implementation The code that manages this is in read-from-disk.service, under loadGuppyProjects:

Right now we're silently swallowing these errors.

We could throw a prompt right there in the .catch, but that would mean 1 prompt for every deleted project. If the user deletes 10 projects, that's a lot of prompts!

Instead, we want to bubble those errors in with the results. So if we're loading 5 projects and 2 were deleted, the value passed to results might look like this:

[ project1Json, Error, Error, project4Json, project5Json]

We should split loadGuppyProjects up into a couple functions; one to parse the disk and return results, and then another to build a valid projects object out of it.

Here's the flow I imagine, in refresh-projects.saga.js:

const pathsArray = yield select(getPathsArray);

const projectsFromDisk = yield call(loadGuppyProjects, pathsArray);
// This will now be that array of mixed JSON and errors

const deletedPaths = /* some method that finds the paths in `pathsArray` that produced errors */

if (deletedPaths.length > 0) {
  const deletedProjectNames = /* some method that converts deletedPaths to projectNames */
  
  const message = /* some method to build up a nice error message, taking into account the number of projects for proper grammar */

  dialog.showMessageBox({...});
}

As a bonus, this would set us up well to handle other types of errors when loading projects.

贡献者指南