Skip to content

Commit fd5f0fa

Browse files
authored
Merge pull request #99 from codeitcodes/dev
Dev
2 parents 691e42f + 853541e commit fd5f0fa

File tree

5 files changed

+107
-45
lines changed

5 files changed

+107
-45
lines changed

filebrowser.js

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -59,35 +59,18 @@ async function renderSidebarHTML() {
5959

6060
let resp;
6161

62-
try {
63-
64-
// if navigating in repository
65-
if (repo != '') {
66-
67-
// render branch menu
68-
renderBranchMenuHTML();
69-
70-
}
71-
72-
// get items in current tree from git
73-
resp = await git.getItems(treeLoc);
74-
75-
} catch(e) {
76-
77-
// if failed to get items,
78-
// show login screen
79-
80-
// stop loading
81-
stopLoading();
82-
83-
alert('Whoops, your Github login expired. Log in again?');
84-
85-
sidebar.classList.add('intro');
62+
// if navigating in repository
63+
if (repo != '') {
8664

87-
return;
65+
// render branch menu
66+
renderBranchMenuHTML();
8867

8968
}
9069

70+
// get items in current tree from git
71+
resp = await git.getItems(treeLoc);
72+
73+
9174
if (resp.message == 'Not Found') {
9275

9376
// if couldn't find repository, show not found screen
@@ -263,6 +246,9 @@ async function renderSidebarHTML() {
263246
// if navigating in repository
264247
if (repo != '') {
265248

249+
// change header options
250+
header.classList.remove('out-of-repo');
251+
266252
// render files
267253
resp.forEach(item => {
268254

@@ -378,6 +364,9 @@ async function renderSidebarHTML() {
378364

379365
} else { // else, show all repositories
380366

367+
// change header options
368+
header.classList.add('out-of-repo');
369+
381370
// hide branch button
382371
sidebarBranch.classList.remove('visible');
383372

@@ -969,19 +958,21 @@ async function renderBranchMenuHTML(renderAll) {
969958
// save resp in HTML
970959
setAttr(branchMenu, 'resp', JSON.stringify(cleanedResp));
971960

972-
973-
if (branchResp.length > 1) {
974-
975-
sidebarBranch.classList.add('visible');
976-
977-
} else {
978-
979-
return;
980-
981-
}
982-
983961
}
962+
963+
964+
// if repository has more than one branch,
965+
// show branch button
966+
if (branchResp && branchResp.length > 1) {
967+
968+
sidebarBranch.classList.add('visible');
969+
970+
} else {
984971

972+
return;
973+
974+
}
975+
985976

986977
// save rendered HTML
987978
let out = '';
@@ -1247,7 +1238,7 @@ function checkBranchMenu(e) {
12471238
addButton.addEventListener('click', () => {
12481239

12491240
// if navigating in repository
1250-
if (treeLoc[1] != '') {
1241+
if (!header.classList.contains('out-of-repo')) {
12511242

12521243
// create new file
12531244
createNewFileInHTML();
@@ -1376,7 +1367,7 @@ function createNewRepoInHTML() {
13761367
startLoading();
13771368

13781369
// push repo asynchronously
1379-
const newSha = await git.createRepo(repoName);
1370+
const newSha = await git.createRepo(repoName, true);
13801371

13811372
// stop loading
13821373
stopLoading();

full.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,7 @@ body.notransition .sidebar {
756756
background: #568af2;
757757
background: var(--rosemary-lighter);
758758
transition: width .4s ease, opacity .4s linear;
759+
overscroll-behavior: none;
759760
z-index: 1000;
760761
}
761762

@@ -771,6 +772,7 @@ body.notransition .sidebar {
771772
display: flex;
772773
align-items: center;
773774
justify-content: right;
775+
overscroll-behavior: none;
774776
overflow: hidden;
775777
z-index: 100;
776778
}
@@ -894,6 +896,10 @@ body.notransition .sidebar {
894896
display: block;
895897
}
896898

899+
.sidebar .header.out-of-repo .title .branch-icon {
900+
display: none;
901+
}
902+
897903
body:not(.mobile) .sidebar .header .title .branch-icon:hover {
898904
opacity: 0.72;
899905
}
@@ -1288,7 +1294,7 @@ body:not(.mobile) .sidebar .header .title .branch-icon:active {
12881294

12891295
.sidebar .picture-wrapper {
12901296
background: hsl(228deg 38% 21%);
1291-
color: rgba(241,241,242,0.8);
1297+
color: hsl(223deg 92% 87%);
12921298
height: 120px;
12931299
width: 120px;
12941300
overflow: hidden;

git/gitapi.js

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,22 @@ let git = {
104104

105105
},
106106

107-
'getRepoPushAccess': async (treeLoc, loggedUser) => {
107+
// check if user has push access in repository
108+
'checkPushAccess': async (treeLoc, userToCheck) => {
108109

109110
// map tree location
110111
let query = 'https://api.github.com';
111112
const [user, repo] = treeLoc;
112113

113114
const [repoName] = repo.split(':');
114115

115-
query += '/repos/' + user + '/' + repoName + '/collaborators/' + loggedUser + '/permission';
116+
query += '/repos/' + user + '/' + repoName + '/collaborators/' + userToCheck + '/permission';
116117

117118
// get the query
118119
const resp = await axios.get(query, gitToken);
119120

120121
if (resp.message &&
121-
resp.message === 'Must have push access to view collaborator permission.') {
122+
resp.message.startsWith('Must have push access')) {
122123

123124
return false;
124125

@@ -216,20 +217,26 @@ let git = {
216217
},
217218

218219
// create a repository
219-
'createRepo': async (repoName) => {
220+
'createRepo': async (repoName, private) => {
220221

221222
const query = 'https://api.github.com/user/repos';
222223

223224
const repoData = {
224225
name: repoName,
225-
private: true,
226+
private: private,
226227
has_wiki: false,
227228
auto_init: true
228229
};
229230

231+
// change pushing state
232+
changePushingState(true);
233+
230234
// post the query
231235
const resp = await axios.post(query, gitToken, repoData);
232236

237+
// change pushing state
238+
changePushingState(false);
239+
233240
return resp.full_name;
234241

235242
},
@@ -250,10 +257,16 @@ let git = {
250257
ref: 'refs/heads/' + newBranchName,
251258
sha: shaToBranchFrom
252259
};
260+
261+
// change pushing state
262+
changePushingState(true);
253263

254264
// post the query
255265
const resp = await axios.post(query, branchData, gitToken);
256266

267+
// change pushing state
268+
changePushingState(false);
269+
257270
return resp;
258271

259272
},
@@ -267,9 +280,15 @@ let git = {
267280
const query = 'https://api.github.com/repos' +
268281
'/' + user + '/' + repo + '/forks';
269282

283+
// change pushing state
284+
changePushingState(true);
285+
270286
// post the query
271287
const resp = await axios.post(query, gitToken);
272288

289+
// change pushing state
290+
changePushingState(false);
291+
273292
return resp.full_name;
274293

275294
// change treeLoc to fork dir, change all the repo's modified files' dir to the fork's dir, and push modified files in dir.
@@ -286,13 +305,20 @@ let git = {
286305
'/' + user + '/' + repo +
287306
'/collaborators/' + usernameToInvite;
288307

308+
// change pushing state
309+
changePushingState(true);
310+
289311
// put the query
290312
const resp = await axios.put(query, gitToken);
291313

314+
// change pushing state
315+
changePushingState(false);
316+
292317
return resp.node_id;
293318

294319
},
295320

321+
// accept an invitation to a repository
296322
'acceptInviteToRepo': async (treeLoc) => {
297323

298324
// map tree location

service-worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
// update cache names any time any of the cached files change
4-
const CACHE_NAME = 'static-cache-v304';
4+
const CACHE_NAME = 'static-cache-v305';
55

66
// list of files to cache
77
const FILES_TO_CACHE = [

utils.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,3 +647,42 @@ const fileIntroScreen = `
647647
</div>
648648
</div>
649649
`;
650+
651+
652+
const repoNotFoundScreen = `
653+
<div class="intro">
654+
<div class="picture-wrapper" style="margin-bottom: 31.5px;/* margin-bottom: 33.25px; */">
655+
<svg viewBox="0 0 356 415" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" class="picture" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2"><path d="M272.41 168.81c-40.867 0-73.996 33.129-73.996 74V479.6c0 40.867 33.129 73.996 73.996 73.996h14.797c8.176 0 14.801-6.625 14.801-14.801 0-8.172-6.625-14.797-14.801-14.797H272.41c-24.52 0-44.398-19.879-44.398-44.398 0-16.727 9.25-31.293 22.91-38.863 5.828-3 12.902-5.031 21.488-5.535H524v88.797h-29.598c-8.176 0-14.801 6.625-14.801 14.797 0 8.176 6.625 14.801 14.801 14.801h44.395c8.176 0 14.801-6.625 14.801-14.801v-117.06c.871-5.914 0-13.172 0-13.172v-195.35c0-24.52-19.875-44.398-44.398-44.398l-236.79-.006Z" fill="hsl(223deg 92% 87%)" transform="translate(-198.414 -168.81)"></path><path d="M331.6 479.6c0-8.176 6.629-14.801 14.801-14.801h88.797c8.172 0 14.801 6.625 14.801 14.801v88.797a14.797 14.797 0 0 1-7.816 13.047 14.808 14.808 0 0 1-15.195-.734L390.8 556.585l-36.188 24.125a14.804 14.804 0 0 1-23.012-12.313V479.6Z" fill="hsl(223deg 85% 58%)" transform="translate(-198.414 -168.81)"></path></svg>
656+
</div>
657+
<div class="subhead">
658+
<div class="title" style="/* margin-bottom: 10.5px; */margin-bottom: 12.25px;">Hmm... we can't find that repo.</div>
659+
<div class="subtitle">If it's private, try double checking you're on the account with access.</div>
660+
</div>
661+
<div class="button secondary large-spacing-top login" style="/* margin-top: 38.5px; */margin-top: 45.5px;">Close</div>
662+
</div>
663+
`;
664+
665+
const pageErrorScreen = `
666+
<div class="intro">
667+
<div class="picture-wrapper">
668+
<a style="white-space: nowrap;font-size: 58px;font-weight: 600;">🤔</a>
669+
</div>
670+
<div class="subhead">
671+
<div class="title">We couldn't load this page.</div>
672+
</div>
673+
<div class="button secondary medium-spacing-top login">Try again</div>
674+
</div>
675+
`;
676+
677+
const offlineScreen = `
678+
<div class="intro">
679+
<div class="picture-wrapper">
680+
<svg viewBox="0 0 24 24" class="picture"><path d="M1.626 17.87c.125 0 .253-.03.37-.098.36-.205.485-.663.28-1.023-.355-.627-.544-1.343-.544-2.07 0-2.218 1.732-4.02 3.913-4.172.018.282.046.564.096.84.067.36.383.614.738.614.045 0 .09-.004.136-.012.407-.074.678-.465.604-.873-.062-.34-.094-.69-.094-1.04 0-3.204 2.606-5.81 5.81-5.81.58 0 1.15.085 1.702.253.394.123.814-.103.937-.498.12-.396-.103-.815-.5-.937-.69-.21-1.41-.318-2.14-.318-3.673 0-6.714 2.727-7.225 6.262-3.04.118-5.475 2.62-5.475 5.69 0 .986.256 1.958.74 2.81.138.243.39.38.653.38zm18.554-6.802c.03-.312.063-.78.063-1.032 0-.59-.07-1.177-.21-1.745-.1-.4-.503-.645-.907-.55-.402.1-.648.506-.55.908.11.45.167.92.167 1.388 0 .203-.03.615-.055.888-2.067.132-3.816 1.567-4.306 3.603-.097.402.15.808.555.904.397.094.808-.15.904-.554.352-1.46 1.647-2.48 3.15-2.48 1.788 0 3.242 1.455 3.242 3.242s-1.454 3.24-3.24 3.24H8.454c-.414 0-.75.336-.75.75s.336.75.75.75H18.99c2.615 0 4.742-2.126 4.742-4.74 0-2.2-1.514-4.038-3.55-4.57zm.878-8.848c-.293-.293-.768-.293-1.06 0l-19 19c-.294.293-.294.768 0 1.06.145.147.337.22.53.22s.383-.072.53-.22l19-19c.293-.293.293-.767 0-1.06z" fill="currentColor"></path></svg>
681+
</div>
682+
<div class="subhead">
683+
<div class="title">Looks like you're offline.</div>
684+
</div>
685+
<div class="button secondary medium-spacing-top login">Edit modified files</div>
686+
<div class="button teritary tiny-spacing-top login">Try again</div>
687+
</div>
688+
`;

0 commit comments

Comments
 (0)