Skip to content

Commit

Permalink
Merge pull request #30 from muzafferkadir/main
Browse files Browse the repository at this point in the history
feat: added sync files to selected local folder function is created.Yarn package manager fixes, styling fixes. Sass module fix. Added Claude model for open router.
  • Loading branch information
coleam00 authored Oct 24, 2024
2 parents 5a10894 + 368022d commit d40be24
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 7 deletions.
24 changes: 22 additions & 2 deletions app/components/workbench/Workbench.client.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useStore } from '@nanostores/react';
import { motion, type HTMLMotionProps, type Variants } from 'framer-motion';
import { computed } from 'nanostores';
import { memo, useCallback, useEffect } from 'react';
import { memo, useCallback, useEffect, useState } from 'react';
import { toast } from 'react-toastify';
import {
type OnChangeCallback as OnEditorChange,
Expand Down Expand Up @@ -55,6 +55,8 @@ const workbenchVariants = {
export const Workbench = memo(({ chatStarted, isStreaming }: WorkspaceProps) => {
renderLogger.trace('Workbench');

const [isSyncing, setIsSyncing] = useState(false);

const hasPreview = useStore(computed(workbenchStore.previews, (previews) => previews.length > 0));
const showWorkbench = useStore(workbenchStore.showWorkbench);
const selectedFile = useStore(workbenchStore.selectedFile);
Expand Down Expand Up @@ -99,6 +101,21 @@ export const Workbench = memo(({ chatStarted, isStreaming }: WorkspaceProps) =>
workbenchStore.resetCurrentDocument();
}, []);

const handleSyncFiles = useCallback(async () => {
setIsSyncing(true);

try {
const directoryHandle = await window.showDirectoryPicker();
await workbenchStore.syncFiles(directoryHandle);
toast.success('Files synced successfully');
} catch (error) {
console.error('Error syncing files:', error);
toast.error('Failed to sync files');
} finally {
setIsSyncing(false);
}
}, []);

return (
chatStarted && (
<motion.div
Expand Down Expand Up @@ -132,6 +149,10 @@ export const Workbench = memo(({ chatStarted, isStreaming }: WorkspaceProps) =>
<div className="i-ph:code" />
Download Code
</PanelHeaderButton>
<PanelHeaderButton className="mr-1 text-sm" onClick={handleSyncFiles} disabled={isSyncing}>
{isSyncing ? <div className="i-ph:spinner" /> : <div className="i-ph:cloud-arrow-down" />}
{isSyncing ? 'Syncing...' : 'Sync Files'}
</PanelHeaderButton>
<PanelHeaderButton
className="mr-1 text-sm"
onClick={() => {
Expand Down Expand Up @@ -209,7 +230,6 @@ export const Workbench = memo(({ chatStarted, isStreaming }: WorkspaceProps) =>
)
);
});

interface ViewProps extends HTMLMotionProps<'div'> {
children: JSX.Element;
}
Expand Down
38 changes: 34 additions & 4 deletions app/lib/stores/workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,21 +281,22 @@ export class WorkbenchStore {

for (const [filePath, dirent] of Object.entries(files)) {
if (dirent?.type === 'file' && !dirent.isBinary) {
// Remove '/home/project/' from the beginning of the path
// remove '/home/project/' from the beginning of the path
const relativePath = filePath.replace(/^\/home\/project\//, '');

// Split the path into segments
// split the path into segments
const pathSegments = relativePath.split('/');

// If there's more than one segment, we need to create folders
// if there's more than one segment, we need to create folders
if (pathSegments.length > 1) {
let currentFolder = zip;

for (let i = 0; i < pathSegments.length - 1; i++) {
currentFolder = currentFolder.folder(pathSegments[i])!;
}
currentFolder.file(pathSegments[pathSegments.length - 1], dirent.content);
} else {
// If there's only one segment, it's a file in the root
// if there's only one segment, it's a file in the root
zip.file(relativePath, dirent.content);
}
}
Expand All @@ -305,6 +306,35 @@ export class WorkbenchStore {
saveAs(content, 'project.zip');
}

async syncFiles(targetHandle: FileSystemDirectoryHandle) {
const files = this.files.get();
const syncedFiles = [];

for (const [filePath, dirent] of Object.entries(files)) {
if (dirent?.type === 'file' && !dirent.isBinary) {
const relativePath = filePath.replace(/^\/home\/project\//, '');
const pathSegments = relativePath.split('/');
let currentHandle = targetHandle;

for (let i = 0; i < pathSegments.length - 1; i++) {
currentHandle = await currentHandle.getDirectoryHandle(pathSegments[i], { create: true });
}

// create or get the file
const fileHandle = await currentHandle.getFileHandle(pathSegments[pathSegments.length - 1], { create: true });

// write the file content
const writable = await fileHandle.createWritable();
await writable.write(dirent.content);
await writable.close();

syncedFiles.push(relativePath);
}
}

return syncedFiles;
}

async pushToGitHub(repoName: string, githubUsername: string, ghToken: string) {

try {
Expand Down
3 changes: 3 additions & 0 deletions app/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface Window {
showDirectoryPicker(): Promise<FileSystemDirectoryHandle>;
}
2 changes: 2 additions & 0 deletions app/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export const DEFAULT_PROVIDER = 'Anthropic';
const staticModels: ModelInfo[] = [
{ name: 'claude-3-5-sonnet-20240620', label: 'Claude 3.5 Sonnet', provider: 'Anthropic' },
{ name: 'gpt-4o', label: 'GPT-4o', provider: 'OpenAI' },
{ name: 'anthropic/claude-3.5-sonnet', label: 'Anthropic: Claude 3.5 Sonnet (OpenRouter)', provider: 'OpenRouter' },
{ name: 'anthropic/claude-3-haiku', label: 'Anthropic: Claude 3 Haiku (OpenRouter)', provider: 'OpenRouter' },
{ name: 'deepseek/deepseek-coder', label: 'Deepseek-Coder V2 236B (OpenRouter)', provider: 'OpenRouter' },
{ name: 'google/gemini-flash-1.5', label: 'Google Gemini Flash 1.5 (OpenRouter)', provider: 'OpenRouter' },
{ name: 'google/gemini-pro-1.5', label: 'Google Gemini Pro 1.5 (OpenRouter)', provider: 'OpenRouter' },
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"description": "StackBlitz AI Agent",
"private": true,
"license": "MIT",
"packageManager": "[email protected]",
"sideEffects": false,
"type": "module",
"scripts": {
Expand Down Expand Up @@ -96,6 +95,7 @@
"is-ci": "^3.0.1",
"node-fetch": "^3.3.2",
"prettier": "^3.3.2",
"sass-embedded": "^1.80.3",
"typescript": "^5.5.2",
"unified": "^11.0.5",
"unocss": "^0.61.3",
Expand Down
7 changes: 7 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ export default defineConfig((config) => {
chrome129IssuePlugin(),
config.mode === 'production' && optimizeCssModules({ apply: 'build' }),
],
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler',
},
},
},
};
});

Expand Down

0 comments on commit d40be24

Please sign in to comment.