sindresorhus/refined-github

Use the new `toast` component in `restore-file` #4113

fregante posted onGitHub

restore-file changes the menu item inline

But instead of changing the menu, we should use the new toast introduced by https://github.com/sindresorhus/refined-github/pull/4016

gif

Some changes will be needed in the toast to show possible errors. Refer to https://primer.style/css/components/toasts for classnames and icons.


Likewise, we should use the toast in every feature that isn't instantaneous. If you think of any, please list them below.

posted by fregante about 4 years ago

Can I take this? If Yes, Where should I begin?

posted by jayeshmann over 3 years ago

This is our implementation of the toast:

https://github.com/sindresorhus/refined-github/blob/ba878fc91552f41f1860a70864917ca3c40914f4/source/github-helpers/toast.tsx#L17

It needs error handling (just an extra catch + setting the error.message as its message)

And it should be used instead of changing the .textContent in this file:

https://github.com/sindresorhus/refined-github/blob/ba878fc91552f41f1860a70864917ca3c40914f4/source/features/restore-file.tsx#L82

posted by fregante over 3 years ago

Probably you'll want to change this:

https://github.com/sindresorhus/refined-github/blob/ba878fc91552f41f1860a70864917ca3c40914f4/source/features/restore-file.tsx#L86-L109

To something like:

async function restoreFile() {
    const file = await getFile(filePath);

    if (!file) {
        // The file was created by this PR.
        // This code won’t be reached if `highlight-deleted-and-added-files-in-diffs` works.
        throw new Error('Nothing to restore. Delete file instead');
        return;
    }

    if (file.isTruncated) {
        throw new Error('Restore failed: File too big');
        return;
    }

    await commitFileContent(menuItem, file.text, filePath);
}

try {
    const filePath = menuItem.closest<HTMLDivElement>('[data-path]')!.dataset.path!;
    const task = restoreFile(filePath);
    showToast(task);

    // Hide file from view
    await task;
    menuItem.closest('.file')!.remove();
} catch (error: unknown) {
    features.error(__filebasename, error);
}
posted by fregante over 3 years ago

I hope everything is good now!

posted by jayeshmann over 3 years ago

@yakov116 are there other features that might benefit from this? πŸ€”

posted by fregante over 3 years ago

I think the update branch feature and maybe clone-branch, git-reblame.

Basically wherever we are using the loading icon. (On mobile this is what I can think of offhand)

posted by yakov116 over 3 years ago

Basically wherever we are using the loading icon.

Good thinking.

clone-branch

πŸ‘

git-reblame.

I think I prefer the small in-place icon in this case, maybe because it's not an action but a link that will change the current page.

posted by fregante over 3 years ago

Fund this Issue

$0.00
Funded

Pull requests