Skip to content

Commit

Permalink
Changed location of files
Browse files Browse the repository at this point in the history
  • Loading branch information
jarydo committed Oct 19, 2024
1 parent 054561a commit 8a4c504
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 30 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 13 additions & 13 deletions src/content/filesystem.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
"id": "casual_film_critic",
"name": "Casual Film Critic.txt",
"type": "file",
"path": "/src/content/files/casual_film_critic.md"
"path": "/files/casual_film_critic.md"
},
{
"id": "directing",
"name": "Directing.txt",
"type": "file",
"path": "/src/content/files/directing.md"
"path": "/files/directing.md"
},
{
"id": "favourite_films",
"name": "Favourites.txt",
"type": "file",
"path": "/src/content/files/favourite_films.md"
"path": "/files/favourite_films.md"
}
]
},
Expand All @@ -33,13 +33,13 @@
"id": "jamming_with_jaryd",
"name": "Jamming With Jaryd.txt",
"type": "file",
"path": "/src/content/files/jamming_with_jaryd.md"
"path": "/files/jamming_with_jaryd.md"
},
{
"id": "concerts",
"name": "Concerts.txt",
"type": "file",
"path": "/src/content/files/concerts.md"
"path": "/files/concerts.md"
}
]
},
Expand All @@ -52,25 +52,25 @@
"id": "socratica",
"name": "Socratica.txt",
"type": "file",
"path": "/src/content/files/socratica.md"
"path": "/files/socratica.md"
},
{
"id": "mario_kart",
"name": "Mario Kart.txt",
"type": "file",
"path": "/src/content/files/mario_kart.md"
"path": "/files/mario_kart.md"
},
{
"id": "uw_blueprint",
"name": "UW Blueprint.txt",
"type": "file",
"path": "/src/content/files/uw_blueprint.md"
"path": "/files/uw_blueprint.md"
},
{
"id": "doodling",
"name": "Doodling.txt",
"type": "file",
"path": "/src/content/files/doodling.md"
"path": "/files/doodling.md"
}
]
},
Expand All @@ -83,26 +83,26 @@
"id": "resonant",
"name": "Resonant.txt",
"type": "file",
"path": "/src/content/files/resonant.md"
"path": "/files/resonant.md"
},
{
"id": "mini_builds",
"name": "Mini Builds.txt",
"type": "file",
"path": "/src/content/files/mini_builds.md"
"path": "/files/mini_builds.md"
},
{
"id": "personal_site",
"name": "Personal Site.txt",
"type": "file",
"path": "/src/content/files/personal_site.md"
"path": "/files/personal_site.md"
}
]
},
{
"id": "readme",
"name": "README.txt",
"type": "file",
"path": "/src/content/files/README.md"
"path": "/files/README.md"
}
]
65 changes: 48 additions & 17 deletions src/pages/PersonalPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type FileItem = {
name: string;
type: "file" | "folder";
path: string;
content?: string;
children?: FileItem[];
};

Expand All @@ -24,18 +25,18 @@ type WindowState = {
parentId?: string;
};

async function loadMarkdownContent(path: string): Promise<string> {
try {
// Using dynamic import to load markdown files
const content = await import(
/* @vite-ignore */
path
);
return content.markdown;
} catch (error) {
console.error(`Error loading markdown file: ${path}`, error);
return "Error loading content";
}
// Helper function to recursively process the file system
function processFileSystem(items: FileItem[]): FileItem[] {
return items.map((item) => {
if (item.type === "folder" && item.children) {
return { ...item, children: processFileSystem(item.children) };
}
if (item.type === "file" && item.path) {
// For files, we'll load the content here
return { ...item, content: "" }; // Initialize with empty content
}
return item;
});
}

function PersonalPage() {
Expand All @@ -45,12 +46,43 @@ function PersonalPage() {
const [disabledItems, setDisabledItems] = useState<Set<string>>(new Set());

useEffect(() => {
setFileSystem(fileSystemData as FileItem[]);
const processedFileSystem = processFileSystem(fileSystemData as FileItem[]);
setFileSystem(processedFileSystem);

// Load all file contents
const loadAllContents = async () => {
const loadContent = async (items: FileItem[]): Promise<FileItem[]> => {
const promises = items.map(async (item) => {
if (item.type === "file" && item.path) {
try {
const response = await fetch(item.path);
const content = await response.text();
return { ...item, content };
} catch (error) {
console.error(`Error loading file: ${item.path}`, error);
return { ...item, content: "Error loading content" };
}
}
if (item.type === "folder" && item.children) {
const children = await loadContent(item.children);
return { ...item, children };
}
return item;
});

return Promise.all(promises);
};

const updatedFileSystem = await loadContent(processedFileSystem);
setFileSystem(updatedFileSystem);
};

loadAllContents();
}, []);

const isDisabled = (id: string) => disabledItems.has(id);

const openWindow = async (item: FileItem, parentId?: string) => {
const openWindow = (item: FileItem, parentId?: string) => {
// Check if window is already open
const existingWindow = windows.find((w) => w.id === item.id);
if (existingWindow) {
Expand All @@ -65,12 +97,11 @@ function PersonalPage() {
return newSet;
});

if (item.type === "file" && item.name.endsWith(".txt")) {
const content = await loadMarkdownContent(item.path);
if (item.type === "file") {
const newWindow: WindowState = {
id: item.id,
title: item.name,
content: content,
content: item.content || "Error: Content not loaded",
zIndex: maxZIndex + 1,
isOpen: true,
windowType: "text",
Expand Down

0 comments on commit 8a4c504

Please sign in to comment.