@@ -8,10 +8,10 @@ import { fetchRepoNames, fetchBranches, fetchFiles } from "../api/api";
88import { TreeRenderer } from "../domain/TreeRenderer" ;
99
1010import { GitreeContextType } from "./types" ;
11- import { actions } from "./actions" ;
1211import { reducer } from "./reducer" ;
1312import { initialState } from "./initialState" ;
1413import { storeOwner , storeToken } from "./storage" ;
14+ import { ActionTypes } from "./actions" ;
1515
1616export const GitreeContext = React . createContext < GitreeContextType | null > (
1717 null ,
@@ -22,35 +22,35 @@ export const GitreeProvider = ({ children }: { children: React.ReactNode }) => {
2222 const value : GitreeContextType = {
2323 state,
2424 setOwnerFormCollapsed : ( collapsed : boolean ) => {
25- dispatch ( { type : actions . SET_OWNER_FORM_COLLAPSED , collapsed } ) ;
25+ dispatch ( { type : ActionTypes . SET_OWNER_FORM_COLLAPSED , collapsed } ) ;
2626 } ,
2727 setOwner : ( owner : string ) => {
28- dispatch ( { type : actions . SET_OWNER , owner } ) ;
28+ dispatch ( { type : ActionTypes . SET_OWNER , owner } ) ;
2929 } ,
3030 setToken : ( token : string ) => {
31- dispatch ( { type : actions . SET_TOKEN , token } ) ;
31+ dispatch ( { type : ActionTypes . SET_TOKEN , token } ) ;
3232 } ,
3333 getRepos : async ( ) => {
34- dispatch ( { type : actions . FETCH_REPOS } ) ;
34+ dispatch ( { type : ActionTypes . FETCH_REPOS } ) ;
3535 const { owner, token } = state . ownerData ;
3636 try {
3737 const repos = await fetchRepoNames ( owner , token ) ;
3838 if ( ! repos . length ) {
3939 dispatch ( {
40- type : actions . SET_REPOS ,
40+ type : ActionTypes . SET_REPOS ,
4141 error :
4242 "This user appears to have no repos. Why don't you try another one?" ,
4343 repos,
4444 } ) ;
4545 } else {
46- dispatch ( { type : actions . SET_REPOS , error : null , repos } ) ;
46+ dispatch ( { type : ActionTypes . SET_REPOS , error : null , repos } ) ;
4747 storeOwner ( owner ) ;
4848 storeToken ( token ) ;
4949 }
5050 } catch ( e ) {
5151 if ( e instanceof Error ) {
5252 dispatch ( {
53- type : actions . SET_REPOS ,
53+ type : ActionTypes . SET_REPOS ,
5454 error : `Can't fetch repos: ${ e . message } .` ,
5555 repos : [ ] ,
5656 } ) ;
@@ -61,13 +61,13 @@ export const GitreeProvider = ({ children }: { children: React.ReactNode }) => {
6161 } ,
6262
6363 setRepoFormCollapsed : ( collapsed : boolean ) => {
64- dispatch ( { type : actions . SET_REPO_FORM_COLLAPSED , collapsed } ) ;
64+ dispatch ( { type : ActionTypes . SET_REPO_FORM_COLLAPSED , collapsed } ) ;
6565 } ,
6666 setRepo : ( repo : string ) => {
67- dispatch ( { type : actions . SET_REPO , repo } ) ;
67+ dispatch ( { type : ActionTypes . SET_REPO , repo } ) ;
6868 } ,
6969 getBranches : async ( ) => {
70- dispatch ( { type : actions . FETCH_BRANCHES } ) ;
70+ dispatch ( { type : ActionTypes . FETCH_BRANCHES } ) ;
7171 const { owner, token } = state . ownerData ;
7272 const { repo } = state . repoData ;
7373 try {
@@ -78,7 +78,7 @@ export const GitreeProvider = ({ children }: { children: React.ReactNode }) => {
7878 const branches = await fetchBranches ( owner , token , repo ) ;
7979 if ( ! branches . length ) {
8080 dispatch ( {
81- type : actions . SET_BRANCHES ,
81+ type : ActionTypes . SET_BRANCHES ,
8282 error :
8383 "This repo appears to have no branches. Why don't you try another one?" ,
8484 branches,
@@ -89,7 +89,7 @@ export const GitreeProvider = ({ children }: { children: React.ReactNode }) => {
8989 ( b : Branch ) => b . name === "master" || b . name === "main" ,
9090 ) ;
9191 dispatch ( {
92- type : actions . SET_BRANCHES ,
92+ type : ActionTypes . SET_BRANCHES ,
9393 error : null ,
9494 branches,
9595 branch : masterBranch ?? null ,
@@ -98,7 +98,7 @@ export const GitreeProvider = ({ children }: { children: React.ReactNode }) => {
9898 } catch ( e ) {
9999 if ( e instanceof Error ) {
100100 dispatch ( {
101- type : actions . SET_BRANCHES ,
101+ type : ActionTypes . SET_BRANCHES ,
102102 error : `Can't fetch branches: ${ e . message } .` ,
103103 branches : [ ] ,
104104 branch : null ,
@@ -110,13 +110,13 @@ export const GitreeProvider = ({ children }: { children: React.ReactNode }) => {
110110 } ,
111111
112112 setBranchFormCollapsed : ( collapsed : boolean ) => {
113- dispatch ( { type : actions . SET_BRANCH_FORM_COLLAPSED , collapsed } ) ;
113+ dispatch ( { type : ActionTypes . SET_BRANCH_FORM_COLLAPSED , collapsed } ) ;
114114 } ,
115115 setBranch : ( branch : Branch ) => {
116- dispatch ( { type : actions . SET_BRANCH , branch } ) ;
116+ dispatch ( { type : ActionTypes . SET_BRANCH , branch } ) ;
117117 } ,
118118 buildTree : async ( ) => {
119- dispatch ( { type : actions . FETCH_FILES } ) ;
119+ dispatch ( { type : ActionTypes . FETCH_FILES } ) ;
120120 const { owner, token } = state . ownerData ;
121121 const { repo } = state . repoData ;
122122 const { branch } = state . branchData ;
@@ -133,7 +133,7 @@ export const GitreeProvider = ({ children }: { children: React.ReactNode }) => {
133133 ) ;
134134
135135 dispatch ( {
136- type : actions . BUILD_TREE ,
136+ type : ActionTypes . BUILD_TREE ,
137137 error : null ,
138138 files,
139139 tree : buildTree ( `${ repo } @${ branch ! . name } ` , files ) ,
@@ -142,7 +142,7 @@ export const GitreeProvider = ({ children }: { children: React.ReactNode }) => {
142142 } catch ( e ) {
143143 if ( e instanceof Error ) {
144144 dispatch ( {
145- type : actions . BUILD_TREE ,
145+ type : ActionTypes . BUILD_TREE ,
146146 error : `Can't fetch files: ${ e . message } .` ,
147147 files : [ ] ,
148148 tree : null ,
@@ -155,13 +155,13 @@ export const GitreeProvider = ({ children }: { children: React.ReactNode }) => {
155155 } ,
156156
157157 setRenderer : ( renderer : TreeRenderer ) => {
158- dispatch ( { type : actions . SET_RENDERER , renderer } ) ;
158+ dispatch ( { type : ActionTypes . SET_RENDERER , renderer } ) ;
159159 } ,
160160 setHoveredNode : ( hoveredNode : Node | null ) => {
161- dispatch ( { type : actions . SET_HOVERED_NODE , hoveredNode } ) ;
161+ dispatch ( { type : ActionTypes . SET_HOVERED_NODE , hoveredNode } ) ;
162162 } ,
163163 setMainNode : ( mainNode : Node | null ) => {
164- dispatch ( { type : actions . SET_MAIN_NODE , mainNode } ) ;
164+ dispatch ( { type : ActionTypes . SET_MAIN_NODE , mainNode } ) ;
165165 } ,
166166 } ;
167167
0 commit comments