Skip to content

Commit 32a6e77

Browse files
committed
Fixes to renaming FSObjects
1 parent 102194b commit 32a6e77

10 files changed

Lines changed: 63 additions & 43 deletions

File tree

src/components/BorderedApp/BorderedApp.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ function BorderedApp({
7474
function onClickClose() {
7575
winMan.closeWindow(type, id);
7676
}
77-
console.log("Bordered app, hidden", String(hidden));
7877

7978
return (
8079
<StyledBorderedApp

src/components/BottomBar/Launcher/Launcher.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ function Launcher({
6666
// we want to focus them. This means revealing them if they
6767
// are minimized and bring them to the top of the window stack.
6868
if (winMan.windowsOfTypeExist(windowType)) {
69-
console.log("Attempting to focus windows");
7069
winMan.focusWindowsOfType(windowType);
7170
return;
7271
}
@@ -111,7 +110,6 @@ function Launcher({
111110
function getContextPosition(numberOfItems: number): Position {
112111
const rect = ref.current?.getBoundingClientRect();
113112
if (!rect) return { x: 0, y: 0 };
114-
console.log(rect);
115113
return {
116114
x: rect.x,
117115
y: rect.y - 20 - numberOfItems * 30,

src/components/Button/Button.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@ interface ButtonProps {
44
name: string;
55
onClick: () => void;
66
width?: string | number;
7+
disabled?: boolean;
78
}
89

9-
function Button({ name, width = "100%", onClick }: ButtonProps) {
10+
function Button({
11+
name,
12+
width = "100%",
13+
disabled = false,
14+
onClick,
15+
}: ButtonProps) {
1016
return (
11-
<StyledButton width={width} onClick={onClick}>
17+
<StyledButton width={width} onClick={onClick} disabled={disabled}>
1218
{name}
1319
</StyledButton>
1420
);

src/hooks/useLocalFSWithHistory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function useLocalFSWithHistory(currentPath: string) {
6262
getDirOrDefault,
6363
navForward,
6464
navBack,
65+
getNameFromPath: fs.getLastFromPath,
6566
};
6667
}
6768

src/programs/FileBrowser/DirectoryOrFile/DirectoryOrFile.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function DirectoryOrFile({
8585
/>
8686
)}
8787
{isFSDirectory(fsObject) ? (
88-
<StyledFolderIcon fillColor={settings.iconColor} />
88+
<StyledFolderIcon fill={settings.iconColor} />
8989
) : null}
9090
<StyledItemName>{fsObject.name}</StyledItemName>
9191
</StyledItem>
@@ -155,7 +155,11 @@ function RenamePopup({
155155

156156
<Row>
157157
<Button name="Cancel" onClick={close} />
158-
<Button name="Confirm" onClick={handleClickConfirm} />
158+
<Button
159+
name="Confirm"
160+
onClick={handleClickConfirm}
161+
disabled={!!error}
162+
/>
159163
</Row>
160164
</Box>
161165
</AppPopup>

src/programs/FileBrowser/DirectoryOrFile/styles.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ export const StyledItem = styled.div<{
2424

2525
export const StyledItemName = styled.span``;
2626

27-
export const StyledFolderIcon = styled(FolderIcon)<{ fillColor: string }>`
27+
export const StyledFolderIcon = styled(FolderIcon)<{ fill: string }>`
2828
height: 80%;
2929
width: 80%;
3030
path {
31-
fill: ${(props) => props.fillColor};
31+
fill: ${(props) => props.fill};
3232
}
3333
`;

src/programs/FileBrowser/FileBrowser.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ function FileBrowser({ path = defaultPath }: FileBrowserProps) {
8282

8383
<AppSideBar
8484
items={fs.favorites.map((fav) => ({
85-
title: fav.name,
86-
isActive: fav.path === fs.currentDirectory.path,
87-
onClick: () => fs.navToPath(fav.path),
85+
title: fs.getNameFromPath(fav) ?? "",
86+
isActive: fav === fs.currentDirectory.path,
87+
onClick: () => fs.navToPath(fav),
8888
}))}
8989
/>
9090

src/programs/FileBrowser/MainContent/MainContent.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ function CreateFSObjectPopup({
134134

135135
<Row>
136136
<Button name="Cancel" onClick={close} />
137-
<Button name="Confirm" onClick={handleClickConfirm} />
137+
<Button
138+
name="Confirm"
139+
onClick={handleClickConfirm}
140+
disabled={!!error}
141+
/>
138142
</Row>
139143
</Box>
140144
</AppPopup>

src/stores/localFS.ts

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,53 +20,49 @@ export type FSObject = FSDirectory | FSFile;
2020
export type FSObjectType = FSObject["type"];
2121

2222
const pathSeparator = "/";
23+
const rootDirPath = "/";
24+
const homeDirPath = rootDirPath + "home";
25+
const userDirPath = [homeDirPath, "user"].join(pathSeparator);
26+
const documentsDirPath = [userDirPath, "Documents"].join(pathSeparator);
27+
const picturesDirPath = [userDirPath, "Pictures"].join(pathSeparator);
28+
const downloadsDirPath = [userDirPath, "Downloads"].join(pathSeparator);
29+
const musicDirPath = [userDirPath, "Music"].join(pathSeparator);
30+
const videosDirPath = [userDirPath, "Videos"].join(pathSeparator);
2331

2432
const documentsDir: FSDirectory = {
2533
name: "Documents",
26-
get path() {
27-
return [userDir.path, this.name].join(pathSeparator);
28-
},
34+
path: documentsDirPath,
2935
type: "directory",
3036
contents: {},
3137
};
3238
const picturesDir: FSDirectory = {
3339
name: "Pictures",
34-
get path() {
35-
return [userDir.path, this.name].join(pathSeparator);
36-
},
40+
path: picturesDirPath,
3741
type: "directory",
3842
contents: {},
3943
};
4044
const downloadsDir: FSDirectory = {
4145
name: "Downloads",
42-
get path() {
43-
return [userDir.path, this.name].join(pathSeparator);
44-
},
46+
path: downloadsDirPath,
4547
type: "directory",
4648
contents: {},
4749
};
4850
const musicDir: FSDirectory = {
4951
name: "Music",
50-
get path() {
51-
return [userDir.path, this.name].join(pathSeparator);
52-
},
52+
path: musicDirPath,
5353
type: "directory",
5454
contents: {},
5555
};
5656
const videosDir: FSDirectory = {
5757
name: "Videos",
58-
get path() {
59-
return [userDir.path, this.name].join(pathSeparator);
60-
},
58+
path: videosDirPath,
6159
type: "directory",
6260
contents: {},
6361
};
6462

6563
const userDir: FSDirectory = {
6664
name: "user",
67-
get path() {
68-
return [homeDir.path, this.name].join(pathSeparator);
69-
},
65+
path: userDirPath,
7066
type: "directory",
7167
contents: {
7268
[documentsDir.name]: documentsDir,
@@ -79,9 +75,7 @@ const userDir: FSDirectory = {
7975

8076
const homeDir: FSDirectory = {
8177
name: "home",
82-
get path() {
83-
return pathSeparator + this.name;
84-
},
78+
path: homeDirPath,
8579
type: "directory",
8680
contents: { [userDir.name]: userDir },
8781
};
@@ -113,7 +107,7 @@ export interface LocalFSState {
113107
parentDirectory: FSDirectory,
114108
contents?: string
115109
) => FSFile | null;
116-
favorites: Array<{ path: string; name: string }>;
110+
favorites: Array<string>;
117111
validateFSObjectName: (name: string) => string | null;
118112
fsObjectNameIsAvailable: (name: string, directory: FSDirectory) => boolean;
119113
create: (
@@ -278,24 +272,39 @@ export const useLocalFS = create<LocalFSState>()(
278272
newName
279273
) => {
280274
const oldName = fsObject.name;
275+
const oldPath = fsObject.path;
276+
277+
// Update the FSObject to have the new name
281278
fsObject.name = newName;
282279
fsObject.path = [
283280
...fsObject.path.split(pathSeparator).slice(0, -1),
284281
newName,
285282
].join(pathSeparator);
286-
parentDirectory.contents[newName] = fsObject;
283+
284+
// Delete the old one from the parent
287285
delete parentDirectory.contents[oldName];
288286

289-
set({ root: get().root });
287+
// Update the parent so it knows about the rename
288+
parentDirectory.contents[newName] = fsObject;
289+
290+
// If the FSObject is in the favorites, update that too.
291+
const favorites = get().favorites;
292+
const favIndex = favorites.findIndex((fav) => fav === oldPath);
293+
if (favIndex) {
294+
favorites[favIndex] = fsObject.path;
295+
}
296+
297+
set({ root: get().root, favorites });
290298
};
291299
return {
292300
root: rootDir,
293301
favorites: [
294-
{ name: userDir.name, path: userDir.path },
295-
{ name: documentsDir.name, path: documentsDir.path },
296-
{ name: downloadsDir.name, path: downloadsDir.path },
297-
{ name: musicDir.name, path: musicDir.path },
298-
{ name: videosDir.name, path: videosDir.path },
302+
userDir.path,
303+
documentsDir.path,
304+
downloadsDir.path,
305+
musicDir.path,
306+
picturesDir.path,
307+
videosDir.path,
299308
],
300309
create,
301310
createDirectory,

src/stores/windowManagerStore.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ const useWindowManagerStore = create<WindowManagerStoreState>()((set, get) => ({
8585
const windowsOfType = windowsMap.get(windowType);
8686

8787
// If no windows of this type exist, nothing to do
88-
console.log(`${windowsOfType?.size} Windows of type ${windowType}`);
8988
if (!windowsOfType?.size) return;
9089

9190
let highestZIndex = get().highestZIndex;

0 commit comments

Comments
 (0)