Skip to content

Commit 432d867

Browse files
sumomomomomolinedoestrolling
authored andcommitted
Make folder name appear on the bar
1 parent af32c59 commit 432d867

File tree

8 files changed

+43
-25
lines changed

8 files changed

+43
-25
lines changed

src/commons/controlBar/ControlBarGoogleDriveButtons.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { IconNames } from '@blueprintjs/icons';
33
import { Popover2, Tooltip2 } from '@blueprintjs/popover2';
44
import React from 'react';
55

6-
import { PersistenceFile, PersistenceState } from '../../features/persistence/PersistenceTypes';
6+
import { PersistenceObject, PersistenceState } from '../../features/persistence/PersistenceTypes';
77
import ControlButton from '../ControlButton';
88
import { useResponsive } from '../utils/Hooks';
99

@@ -17,7 +17,7 @@ type Props = {
1717
isFolderModeEnabled: boolean;
1818
loggedInAs?: string;
1919
accessToken?: string;
20-
currentFile?: PersistenceFile;
20+
currentObject?: PersistenceObject;
2121
isDirty?: boolean;
2222
onClickOpen?: () => any;
2323
onClickSave?: () => any;
@@ -30,14 +30,14 @@ type Props = {
3030

3131
export const ControlBarGoogleDriveButtons: React.FC<Props> = props => {
3232
const { isMobileBreakpoint } = useResponsive();
33-
const state: PersistenceState = props.currentFile
33+
const state: PersistenceState = props.currentObject
3434
? props.isDirty
3535
? 'DIRTY'
3636
: 'SAVED'
3737
: 'INACTIVE';
3838
const mainButton = (
3939
<ControlButton
40-
label={(props.currentFile && props.currentFile.name) || 'Google Drive'}
40+
label={(props.currentObject && props.currentObject.name) || 'Google Drive'}
4141
icon={IconNames.CLOUD}
4242
options={{ intent: stateToIntent[state] }}
4343
//isDisabled={props.isFolderModeEnabled}

src/commons/sagas/PersistenceSaga.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
PERSISTENCE_SAVE_ALL,
1111
PERSISTENCE_SAVE_FILE,
1212
PERSISTENCE_SAVE_FILE_AS,
13-
PersistenceFile
13+
PersistenceObject
1414
} from '../../features/persistence/PersistenceTypes';
1515
import { store } from '../../pages/createStore';
1616
import { OverallState } from '../application/ApplicationTypes';
@@ -142,6 +142,8 @@ export function* persistenceSaga(): SagaIterator {
142142
}
143143
yield call(console.log, "there is a filesystem");
144144

145+
yield put(actions.playgroundUpdatePersistenceFolder({ id, name, lastSaved: new Date() }));
146+
145147
// rmdir everything TODO replace everything hardcoded with playground?
146148
yield call(rmFilesInDirRecursively, fileSystem, "/playground");
147149

@@ -171,6 +173,8 @@ export function* persistenceSaga(): SagaIterator {
171173

172174
yield call(showSuccessMessage, `Loaded folder ${name}.`, 1000);
173175

176+
// TODO the Google Drive button isn't blue even after loading stuff
177+
174178
return;
175179
}
176180

@@ -196,7 +200,7 @@ export function* persistenceSaga(): SagaIterator {
196200
if (meta && meta.appProperties) {
197201
yield put(
198202
actions.chapterSelect(
199-
parseInt(meta.appProperties.chapter || '4', 10) as Chapter, // how does this work??
203+
parseInt(meta.appProperties.chapter || '4', 10) as Chapter,
200204
meta.appProperties.variant || Variant.DEFAULT,
201205
'playground'
202206
)
@@ -251,9 +255,9 @@ export function* persistenceSaga(): SagaIterator {
251255
}
252256
);
253257

254-
const saveToDir: PersistenceFile = pickedDir.picked
255-
? pickedDir
256-
: { id: ROOT_ID, name: 'My Drive' };
258+
const saveToDir: PersistenceObject = pickedDir.picked // TODO is there a better way?
259+
? {...pickedDir}
260+
: { id: ROOT_ID, name: 'My Drive'};
257261

258262
const pickedFile: PickFileResult = yield call(
259263
pickFile,
@@ -597,7 +601,7 @@ function createFile(
597601
mimeType: string,
598602
contents: string = '',
599603
config: IPlaygroundConfig | {}
600-
): Promise<PersistenceFile> {
604+
): Promise<PersistenceObject> {
601605
const name = filename;
602606
const meta = {
603607
name,
@@ -621,7 +625,7 @@ function createFile(
621625
headers,
622626
body
623627
})
624-
.then(({ result }) => ({ id: result.id, name: result.name }));
628+
.then(({ result }) => ({ id: result.id, name: result.name, isFile: true }));
625629
}
626630

627631
function updateFile(

src/commons/sagas/__tests__/PersistenceSaga.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ test('PERSISTENCE_SAVE_FILE saves', () => {
189189
}
190190
}
191191
})
192-
.dispatch(actions.persistenceSaveFile({ id: FILE_ID, name: FILE_NAME }))
192+
.dispatch(actions.persistenceSaveFile({ id: FILE_ID, name: FILE_NAME}))
193193
.provide({
194194
call(effect, next) {
195195
switch (effect.fn.name) {

src/features/persistence/PersistenceTypes.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ export const PERSISTENCE_INITIALISE = 'PERSISTENCE_INITIALISE';
66

77
export type PersistenceState = 'INACTIVE' | 'SAVED' | 'DIRTY';
88

9-
export type PersistenceFile = {
9+
export type PersistenceObject = {
1010
id: string;
1111
name: string;
1212
lastSaved?: Date;
13-
};
13+
isFolder?: boolean;
14+
};

src/features/playground/PlaygroundActions.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { createAction } from '@reduxjs/toolkit';
22
import { SALanguage } from 'src/commons/application/ApplicationTypes';
33

4-
import { PersistenceFile } from '../persistence/PersistenceTypes';
4+
import { PersistenceObject } from '../persistence/PersistenceTypes';
55
import {
66
CHANGE_QUERY_STRING,
77
GENERATE_LZ_STRING,
88
PLAYGROUND_UPDATE_GITHUB_SAVE_INFO,
99
PLAYGROUND_UPDATE_LANGUAGE_CONFIG,
1010
PLAYGROUND_UPDATE_PERSISTENCE_FILE,
11+
PLAYGROUND_UPDATE_PERSISTENCE_FOLDER,
1112
SHORTEN_URL,
1213
UPDATE_SHORT_URL
1314
} from './PlaygroundTypes';
@@ -29,6 +30,11 @@ export const playgroundUpdatePersistenceFile = createAction(
2930
(file?: PersistenceFile) => ({ payload: file })
3031
);
3132

33+
export const playgroundUpdatePersistenceFolder = createAction(
34+
PLAYGROUND_UPDATE_PERSISTENCE_FOLDER,
35+
(file?: PersistenceFile) => ({ payload: file ? {...file, isFolder: true} : undefined})
36+
);
37+
3238
export const playgroundUpdateGitHubSaveInfo = createAction(
3339
PLAYGROUND_UPDATE_GITHUB_SAVE_INFO,
3440
(repoName: string, filePath: string, lastSaved: Date) => ({

src/features/playground/PlaygroundReducer.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
PLAYGROUND_UPDATE_GITHUB_SAVE_INFO,
88
PLAYGROUND_UPDATE_LANGUAGE_CONFIG,
99
PLAYGROUND_UPDATE_PERSISTENCE_FILE,
10+
PLAYGROUND_UPDATE_PERSISTENCE_FOLDER,
1011
PlaygroundState,
1112
UPDATE_SHORT_URL
1213
} from './PlaygroundTypes';
@@ -34,8 +35,13 @@ export const PlaygroundReducer: Reducer<PlaygroundState, SourceActionType> = (
3435
case PLAYGROUND_UPDATE_PERSISTENCE_FILE:
3536
return {
3637
...state,
37-
persistenceFile: action.payload
38+
persistenceObject: action.payload
3839
};
40+
case PLAYGROUND_UPDATE_PERSISTENCE_FOLDER:
41+
return {
42+
...state,
43+
persistenceObject: action.payload
44+
}
3945
case PLAYGROUND_UPDATE_LANGUAGE_CONFIG:
4046
return {
4147
...state,
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import { SALanguage } from 'src/commons/application/ApplicationTypes';
22

33
import { GitHubSaveInfo } from '../github/GitHubTypes';
4-
import { PersistenceFile } from '../persistence/PersistenceTypes';
4+
import { PersistenceObject } from '../persistence/PersistenceTypes';
55

66
export const CHANGE_QUERY_STRING = 'CHANGE_QUERY_STRING';
77
export const GENERATE_LZ_STRING = 'GENERATE_LZ_STRING';
88
export const SHORTEN_URL = 'SHORTEN_URL';
99
export const UPDATE_SHORT_URL = 'UPDATE_SHORT_URL';
1010
export const PLAYGROUND_UPDATE_GITHUB_SAVE_INFO = 'PLAYGROUND_UPDATE_GITHUB_SAVE_INFO';
1111
export const PLAYGROUND_UPDATE_PERSISTENCE_FILE = 'PLAYGROUND_UPDATE_PERSISTENCE_FILE';
12+
export const PLAYGROUND_UPDATE_PERSISTENCE_FOLDER = 'PLAYGROUND_UPDATE_PERSISTENCE_FOLDER';
1213
export const PLAYGROUND_UPDATE_LANGUAGE_CONFIG = 'PLAYGROUND_UPDATE_LANGUAGE_CONFIG';
1314

1415
export type PlaygroundState = {
1516
readonly queryString?: string;
1617
readonly shortURL?: string;
17-
readonly persistenceFile?: PersistenceFile;
18+
readonly persistenceObject?: PersistenceObject;
1819
readonly githubSaveInfo: GitHubSaveInfo;
1920
readonly languageConfig: SALanguage;
2021
};

src/pages/playground/Playground.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ const Playground: React.FC<PlaygroundProps> = props => {
264264
context: { chapter: playgroundSourceChapter, variant: playgroundSourceVariant }
265265
} = useTypedSelector(state => state.workspaces[workspaceLocation]);
266266
const fileSystem = useTypedSelector(state => state.fileSystem.inBrowserFileSystem);
267-
const { queryString, shortURL, persistenceFile, githubSaveInfo } = useTypedSelector(
267+
const { queryString, shortURL, persistenceObject, githubSaveInfo } = useTypedSelector(
268268
state => state.playground
269269
);
270270
const {
@@ -585,12 +585,12 @@ const Playground: React.FC<PlaygroundProps> = props => {
585585

586586
// Compute this here to avoid re-rendering the button every keystroke
587587
const persistenceIsDirty =
588-
persistenceFile && (!persistenceFile.lastSaved || persistenceFile.lastSaved < lastEdit);
588+
persistenceObject && (!persistenceObject.lastSaved || persistenceObject.lastSaved < lastEdit);
589589
const persistenceButtons = useMemo(() => {
590590
return (
591591
<ControlBarGoogleDriveButtons
592592
isFolderModeEnabled={isFolderModeEnabled}
593-
currentFile={persistenceFile}
593+
currentObject={persistenceObject}
594594
loggedInAs={persistenceUser}
595595
isDirty={persistenceIsDirty}
596596
accessToken={googleAccessToken}
@@ -599,7 +599,7 @@ const Playground: React.FC<PlaygroundProps> = props => {
599599
onClickSaveAll={() => dispatch(persistenceSaveAll())}
600600
onClickOpen={() => dispatch(persistenceOpenPicker())}
601601
onClickSave={
602-
persistenceFile ? () => dispatch(persistenceSaveFile(persistenceFile)) : undefined
602+
persistenceObject ? () => dispatch(persistenceSaveFile(persistenceObject)) : undefined
603603
}
604604
onClickLogIn={() => dispatch(loginGoogle())}
605605
onClickLogOut={() => dispatch(logoutGoogle())}
@@ -608,7 +608,7 @@ const Playground: React.FC<PlaygroundProps> = props => {
608608
);
609609
}, [
610610
isFolderModeEnabled,
611-
persistenceFile,
611+
persistenceObject,
612612
persistenceUser,
613613
persistenceIsDirty,
614614
dispatch,
@@ -720,7 +720,7 @@ const Playground: React.FC<PlaygroundProps> = props => {
720720
<ControlBarToggleFolderModeButton
721721
isFolderModeEnabled={isFolderModeEnabled}
722722
isSessionActive={editorSessionId !== ''}
723-
isPersistenceActive={persistenceFile !== undefined || githubSaveInfo.repoName !== ''}
723+
isPersistenceActive={persistenceObject !== undefined || githubSaveInfo.repoName !== ''}
724724
toggleFolderMode={() => dispatch(toggleFolderMode(workspaceLocation))}
725725
key="folder"
726726
/>
@@ -729,7 +729,7 @@ const Playground: React.FC<PlaygroundProps> = props => {
729729
dispatch,
730730
githubSaveInfo.repoName,
731731
isFolderModeEnabled,
732-
persistenceFile,
732+
persistenceObject,
733733
editorSessionId,
734734
workspaceLocation
735735
]);

0 commit comments

Comments
 (0)