diff --git a/libs/remix-api/src/lib/plugins/config-api.ts b/libs/remix-api/src/lib/plugins/config-api.ts new file mode 100644 index 0000000000..e5f072712f --- /dev/null +++ b/libs/remix-api/src/lib/plugins/config-api.ts @@ -0,0 +1,11 @@ +import { StatusEvents } from "@remixproject/plugin-utils" + +export interface IConfigApi { + events: { + configChanged: () => void + } & StatusEvents, + methods: { + getAppParameter(key: string): Promise, + setAppParameter(key: string, value: any): Promise + } +} \ No newline at end of file diff --git a/libs/remix-api/src/lib/plugins/notification-api.ts b/libs/remix-api/src/lib/plugins/notification-api.ts new file mode 100644 index 0000000000..e46b3d493f --- /dev/null +++ b/libs/remix-api/src/lib/plugins/notification-api.ts @@ -0,0 +1,29 @@ +import { ModalTypes } from "@remix-ui/app" +import { StatusEvents } from "@remixproject/plugin-utils" + +export interface INotificationApi { + events: { + + } & StatusEvents, + methods: { + toast(key: string): Promise, + alert({ + title, + message + }:{ + title: string, + message: string, + }): Promise, + modal({ + title, + message, + okLabel, + type + }:{ + title: string, + message: string, + okLabel: string, + type: ModalTypes + }): Promise, + } +} \ No newline at end of file diff --git a/libs/remix-api/src/lib/plugins/settings-api.ts b/libs/remix-api/src/lib/plugins/settings-api.ts new file mode 100644 index 0000000000..dd7323ac73 --- /dev/null +++ b/libs/remix-api/src/lib/plugins/settings-api.ts @@ -0,0 +1,11 @@ +import { StatusEvents } from '@remixproject/plugin-utils' + +export interface ISettings { + events: { + configChanged: () => void, + } & StatusEvents + methods: { + getGithubAccessToken(): string + get(key: string): Promise + } +} diff --git a/libs/remix-api/src/lib/remix-api.ts b/libs/remix-api/src/lib/remix-api.ts index 2a251bcc70..aebd73be26 100644 --- a/libs/remix-api/src/lib/remix-api.ts +++ b/libs/remix-api/src/lib/remix-api.ts @@ -1,9 +1,15 @@ -import { customDGitSystem } from "@remix-ui/git" +import { IGitApi } from "@remix-ui/git" import { IRemixApi } from "@remixproject/plugin-api" import { StatusEvents } from "@remixproject/plugin-utils" +import { IConfigApi } from "./plugins/config-api" +import { INotificationApi } from "./plugins/notification-api" +import { ISettings } from "./plugins/settings-api" export interface ICustomRemixApi extends IRemixApi { - dgitApi: customDGitSystem + dgitApi: IGitApi + config: IConfigApi + notification: INotificationApi + settings: ISettings } export declare type CustomRemixApi = Readonly \ No newline at end of file diff --git a/libs/remix-ui/git/src/components/gitui.tsx b/libs/remix-ui/git/src/components/gitui.tsx index de8c0e034e..1e20d0d9f3 100644 --- a/libs/remix-ui/git/src/components/gitui.tsx +++ b/libs/remix-ui/git/src/components/gitui.tsx @@ -5,7 +5,6 @@ import { openDiff, openFile, saveToken, setModifiedDecorator, setPlugin, setUntr import { gitActionsContext, pluginActionsContext } from '../state/context' import { gitReducer } from '../state/gitreducer' import { defaultGitState, defaultLoaderState, gitState, loaderState } from '../types' - import { Accordion } from "react-bootstrap"; import { CommitMessage } from './buttons/commitmessage' import { Commits } from './panels/commits' @@ -29,7 +28,6 @@ import LogViewer from './panels/log' import { SourceControlBase } from './buttons/sourceControlBase' import { BranchHeader } from './branchHeader' import { SourceControl } from './panels/sourcontrol' -import { Settings } from './panels/settings' import { GitHubCredentials } from './panels/githubcredentials' export const gitPluginContext = React.createContext(defaultGitState) @@ -44,7 +42,6 @@ export const GitUI = (props: IGitUi) => { const [gitState, gitDispatch] = useReducer(gitReducer, defaultGitState) const [loaderState, loaderDispatch] = useReducer(loaderReducer, defaultLoaderState) const [activePanel, setActivePanel] = useState("0"); - const [timeOut, setTimeOut] = useState(null) useEffect(() => { setCallBacks(plugin, gitDispatch, loaderDispatch) @@ -61,8 +58,6 @@ export const GitUI = (props: IGitUi) => { await setUntrackedDecorator(gitState.untracked) } - console.log('gitState.fileStatusResult', gitState.fileStatusResult) - setTimeout(() => { setDecorators(gitState) }) diff --git a/libs/remix-ui/git/src/lib/gitactions.ts b/libs/remix-ui/git/src/lib/gitactions.ts index aab09062e0..7d90fd6b28 100644 --- a/libs/remix-ui/git/src/lib/gitactions.ts +++ b/libs/remix-ui/git/src/lib/gitactions.ts @@ -2,7 +2,7 @@ import { ViewPlugin } from "@remixproject/engine-web"; import { ReadBlobResult, ReadCommitResult } from "isomorphic-git"; import React from "react"; import { fileStatus, fileStatusMerge, setRemoteBranchCommits, resetRemoteBranchCommits, setBranches, setCanCommit, setCommitChanges, setCommits, setCurrentBranch, setGitHubUser, setLoading, setRateLimit, setRemoteBranches, setRemotes, setRepos, setUpstream, setLocalBranchCommits, setBranchDifferences, setRemoteAsDefault, setScopes, setLog, clearLog } from "../state/gitpayload"; -import { GitHubUser, RateLimit, branch, commitChange, gitActionDispatch, statusMatrixType, gitState, branchDifference, remote, gitLog, fileStatusResult, customGitApi, customDGitSystem, cloneInputType, fetchInputType, pullInputType, pushInputType, checkoutInput, rmInput, addInput, repository } from '../types'; +import { GitHubUser, RateLimit, branch, commitChange, gitActionDispatch, statusMatrixType, gitState, branchDifference, remote, gitLog, fileStatusResult, customGitApi, IGitApi, cloneInputType, fetchInputType, pullInputType, pushInputType, checkoutInput, rmInput, addInput, repository } from '../types'; import { removeSlash } from "../utils"; import { disableCallBacks, enableCallBacks } from "./listeners"; import { AlertModal, ModalTypes } from "@remix-ui/app"; @@ -25,7 +25,6 @@ export const fileStatuses = [ ["modified,staged,with unstaged changes", 1, 2, 3], // modified, staged, with unstaged changes ["deleted,unstaged", 1, 0, 1], // deleted, unstaged ["deleted,staged", 1, 0, 0], - //["deleted", 1, 1, 0], // deleted, staged ["unmodified", 1, 1, 3], ["deleted,not in git", 0, 0, 3], ["unstaged,modified", 1, 2, 0] @@ -162,10 +161,10 @@ export const getCommitFromRef = async (ref: string) => { } const settingsWarning = async () => { - const username = await plugin.call('config' as any, 'getAppParameter', 'settings/github-user-name') - const email = await plugin.call('config' as any, 'getAppParameter', 'settings/github-email') + const username = await plugin.call('config', 'getAppParameter', 'settings/github-user-name') + const email = await plugin.call('config', 'getAppParameter', 'settings/github-email') if (!username || !email) { - plugin.call('notification' as any, 'toast', 'Please set your github username and email in the settings') + plugin.call('notification', 'toast', 'Please set your github username and email in the settings') return false; } else { return { @@ -198,7 +197,7 @@ export const commit = async (message: string = "") => { }) } catch (err) { - plugin.call('notification' as any, 'toast', `${err}`) + plugin.call('notification', 'toast', `${err}`) } } @@ -216,7 +215,7 @@ export const addall = async (files: fileStatusResult[]) => { }) } catch (e) { - plugin.call('notification' as any, 'toast', `${e}`) + plugin.call('notification', 'toast', `${e}`) } } @@ -228,7 +227,7 @@ export const add = async (filepath: addInput) => { message: `Added to git` }) } catch (e) { - plugin.call('notification' as any, 'toast', `${e}`) + plugin.call('notification', 'toast', `${e}`) } } @@ -275,7 +274,7 @@ export const checkoutfile = async (filename: string) => { ); await enableCallBacks(); } catch (e) { - plugin.call('notification' as any, 'toast', `No such file`) + plugin.call('notification', 'toast', `No such file`) } } @@ -287,7 +286,7 @@ export const checkout = async (cmd: checkoutInput) => { await plugin.call('dgitApi', 'checkout', cmd) gitlog(); } catch (e) { - plugin.call('notification' as any, 'toast', `${e}`) + plugin.call('notification', 'toast', `${e}`) } await enableCallBacks(); } @@ -376,7 +375,7 @@ const parseError = async (e: any) => { console.trace(e) // if message conttains 401 Unauthorized, show token warning if (e.message.includes('401')) { - const result = await plugin.call('notification' as any, 'modal' as any, { + const result = await plugin.call('notification', 'modal' as any, { title: 'The GitHub token may be missing or invalid', message: 'Please check the GitHub token and try again. Error: 401 Unauthorized', okLabel: 'Go to settings', @@ -387,7 +386,7 @@ const parseError = async (e: any) => { } // if message contains 404 Not Found, show repo not found else if (e.message.includes('404')) { - await plugin.call('notification' as any, 'modal' as any, { + await plugin.call('notification', 'modal' as any, { title: 'Repository not found', message: 'Please check the URL and try again.', okLabel: 'Go to settings', @@ -397,7 +396,7 @@ const parseError = async (e: any) => { } // if message contains 403 Forbidden else if (e.message.includes('403')) { - await plugin.call('notification' as any, 'modal' as any, { + await plugin.call('notification', 'modal' as any, { title: 'The GitHub token may be missing or invalid', message: 'Please check the GitHub token and try again. Error: 403 Forbidden', okLabel: 'Go to settings', @@ -405,14 +404,14 @@ const parseError = async (e: any) => { type: ModalTypes.confirm }) } else if (e.toString().includes('NotFoundError') && !e.toString().includes('fetch')) { - await plugin.call('notification' as any, 'modal', { + await plugin.call('notification', 'modal', { title: 'Remote branch not found', message: 'The branch you are trying to fetch does not exist on the remote. If you have forked this branch from another branch, you may need to fetch the original branch first or publish this branch on the remote.', okLabel: 'OK', type: ModalTypes.alert }) } else { - await plugin.call('notification' as any, 'alert' as any, { + await plugin.call('notification', 'alert' as any, { title: 'Error', message: e.message }) @@ -439,7 +438,7 @@ export const repositories = async () => { } } else { - plugin.call('notification' as any, 'alert', { + plugin.call('notification', 'alert', { title: 'Error getting repositories', message: `Please check your GitHub token in the GitHub settings... cannot connect to GitHub` }) @@ -447,7 +446,7 @@ export const repositories = async () => { } } catch (e) { console.log(e) - plugin.call('notification' as any, 'alert', { + plugin.call('notification', 'alert', { title: 'Error getting repositories', message: `${e.message}: Please check your GitHub token in the GitHub settings.` }) @@ -474,7 +473,7 @@ export const remoteBranches = async (owner: string, repo: string) => { page++ } } else { - plugin.call('notification' as any, 'alert', { + plugin.call('notification', 'alert', { title: 'Error getting branches', message: `Please check your GitHub token in the GitHub settings. It needs to have access to the branches.` }) @@ -482,7 +481,7 @@ export const remoteBranches = async (owner: string, repo: string) => { } } catch (e) { console.log(e) - plugin.call('notification' as any, 'alert', { + plugin.call('notification', 'alert', { title: 'Error', message: e.message }) @@ -516,7 +515,7 @@ export const remoteCommits = async (url: string, branch: string, length: number) } } catch (e) { console.log(e) - plugin.call('notification' as any, 'alert', { + plugin.call('notification', 'alert', { title: 'Error', message: e.message }) diff --git a/libs/remix-ui/git/src/lib/listeners.ts b/libs/remix-ui/git/src/lib/listeners.ts index 452ead1fee..5d6f9a02d1 100644 --- a/libs/remix-ui/git/src/lib/listeners.ts +++ b/libs/remix-ui/git/src/lib/listeners.ts @@ -1,16 +1,14 @@ -import { ViewPlugin } from "@remixproject/engine-web"; import React from "react"; import { setCanUseApp, setLoading, setRepoName, setGItHubToken, setLog } from "../state/gitpayload"; -import { customDGitSystem, gitActionDispatch } from "../types"; +import { gitActionDispatch } from "../types"; import { Plugin } from "@remixproject/engine"; -import { diffFiles, getBranches, getFileStatusMatrix, getGitHubUser, getRemotes, gitlog, setPlugin } from "./gitactions"; +import { getBranches, getFileStatusMatrix, getGitHubUser, getRemotes, gitlog, setPlugin } from "./gitactions"; import { Profile } from "@remixproject/plugin-utils"; import { CustomRemixApi } from "@remix-api"; let plugin: Plugin, gitDispatch: React.Dispatch, loaderDispatch: React.Dispatch, loadFileQueue: AsyncDebouncedQueue let callBackEnabled: boolean = false -let syncTimer: NodeJS.Timer = null type AsyncCallback = () => Promise; @@ -27,7 +25,7 @@ class AsyncDebouncedQueue { } let timer = setTimeout(async () => { - await callback(); // Await the asynchronous operation + await callback(); this.queues.delete(callback); }, customDelay || this.delay); @@ -148,10 +146,10 @@ export const setCallBacks = (viewPlugin: Plugin, gitDispatcher: React.Dispatch { + plugin.on('config', 'configChanged', async () => { await getGitConfig() }) - plugin.on('settings' as any, 'configChanged', async () => { + plugin.on('settings', 'configChanged', async () => { await getGitConfig() }) @@ -159,9 +157,9 @@ export const setCallBacks = (viewPlugin: Plugin, gitDispatcher: React.Dispatch { - const username = await plugin.call('settings' as any, 'get', 'settings/github-user-name') - const email = await plugin.call('settings' as any, 'get', 'settings/github-email') - const token = await plugin.call('settings' as any, 'get', 'settings/gist-access-token') + const username = await plugin.call('settings', 'get', 'settings/github-user-name') + const email = await plugin.call('settings', 'get', 'settings/github-email') + const token = await plugin.call('settings', 'get', 'settings/gist-access-token') const config = { username, email, token } gitDispatch(setGItHubToken(config.token)) return config diff --git a/libs/remix-ui/git/src/types/index.ts b/libs/remix-ui/git/src/types/index.ts index 905c113e27..71c9934ed1 100644 --- a/libs/remix-ui/git/src/types/index.ts +++ b/libs/remix-ui/git/src/types/index.ts @@ -5,7 +5,7 @@ import { CommitObject, ReadBlobResult, ReadCommitResult, StatusRow } from "isomo export type GitHubUser = Endpoints["GET /user"]["response"]['data'] export type RateLimit = Endpoints["GET /rate_limit"]["response"]["data"] -export interface customDGitSystem { +export interface IGitApi { events: { "checkout": () => void "clone": () => void @@ -140,14 +140,14 @@ export interface repositoriesInput { token: string, page?: number, per_page?: nu export interface statusInput { ref: string, filepaths?: string[] } -export const dGitProfile: LibraryProfile = { +export const dGitProfile: LibraryProfile = { name: 'dgitApi', methods: ['clone', 'branches', 'remotes', 'getCommitChanges', 'log', 'remotecommits'], } export interface customGitApi extends IRemixApi { - dgit: customDGitSystem + dgit: IGitApi } export type gitState = { diff --git a/libs/remix-ui/workspace/src/lib/actions/workspace.ts b/libs/remix-ui/workspace/src/lib/actions/workspace.ts index f445788000..e20543fb41 100644 --- a/libs/remix-ui/workspace/src/lib/actions/workspace.ts +++ b/libs/remix-ui/workspace/src/lib/actions/workspace.ts @@ -42,7 +42,7 @@ import { ROOT_PATH, slitherYml, solTestYml, tsSolTestYml } from '../utils/consta import { IndexedDBStorage } from '../../../../../../apps/remix-ide/src/app/files/filesystems/indexedDB' import { getUncommittedFiles } from '../utils/gitStatusFilter' import { AppModal, ModalTypes } from '@remix-ui/app' -import { branch, cloneInputType, customDGitSystem } from '@remix-ui/git' +import { branch, cloneInputType, IGitApi } from '@remix-ui/git' import * as templates from '@remix-project/remix-ws-templates' import { Plugin } from "@remixproject/engine"; import { CustomRemixApi } from '@remix-api'