Skip to content

Commit

Permalink
remove console.log
Browse files Browse the repository at this point in the history
  • Loading branch information
yuiseki committed Nov 7, 2024
1 parent 07aa600 commit 76bb549
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
38 changes: 33 additions & 5 deletions src/app/charites/TridentFileSystem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export const TridentFileSystem: React.FC = () => {
// layers ディレクトリ内のファイルリストを取得して表示
const files: string[] = [];
for await (const [name, entry] of layersDirHandle.entries()) {
console.info(name);
if (entry.kind === "file") {
files.push(entry.name);
}
Expand All @@ -84,6 +83,35 @@ export const TridentFileSystem: React.FC = () => {
}
};

// 全ファイルの内容のEmbeddingsを更新する
const updateEmbeddings = useCallback(async () => {
try {
// rootDirHandleに基づいてファイルシステム内の全ファイルパスと内容をresultsに格納する再帰関数、walk
const results: { path: string; text: string }[] = [];
const rootDirHandle = await navigator.storage.getDirectory();
const walk = async (
dirHandle: FileSystemDirectoryHandle,
path: string
) => {
for await (const [name, entry] of dirHandle.entries()) {
if (entry.kind === "file") {
const fileHandle = entry as FileSystemFileHandle;
const file = await fileHandle.getFile();
const text = await file.text();
results.push({ path: path + name, text });
} else {
const subDirHandle = await dirHandle.getDirectoryHandle(name);
await walk(subDirHandle, path + name + "/");
}
}
};
await walk(rootDirHandle, "");
console.log(results);
} catch (error) {
console.error(error);
}
}, []);

// ファイルシステムの内容全体を地図に反映する
const updateMapStyleJson = useCallback(async () => {
try {
Expand All @@ -95,7 +123,6 @@ export const TridentFileSystem: React.FC = () => {
setNotification(
"ファイルシステム内のYAMLをJSONに変換しました。地図を描画します"
);
console.log(JSON.stringify(data, null, 2));
} catch (error) {
console.error(error);
setNotification(
Expand All @@ -106,7 +133,6 @@ export const TridentFileSystem: React.FC = () => {

// エディターの内容をファイルシステムに保存する
const saveFile = useCallback(async () => {
console.log("saveFile");
if (!fileHandle) return;

try {
Expand All @@ -121,7 +147,8 @@ export const TridentFileSystem: React.FC = () => {

// ファイル保存後に内容を反映
await updateMapStyleJson();
}, [content, fileHandle, updateMapStyleJson]);
await updateEmbeddings();
}, [content, fileHandle, updateEmbeddings, updateMapStyleJson]);

// Ctrl + S で保存
useKeyBind({
Expand Down Expand Up @@ -159,9 +186,10 @@ export const TridentFileSystem: React.FC = () => {
const initializeAndSave = async () => {
await initializeFileSystem();
await updateMapStyleJson();
await updateEmbeddings();
};
void initializeAndSave();
// eslint-disable-next-line react-hooks/exhaustive-deps
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
Expand Down
2 changes: 0 additions & 2 deletions src/utils/parseYaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ export const parseYamlWithIncludes = async (
text = text.replace(match[0], includedYamlText);
}

console.log(text);

// すべての !!inc/file を置換した後にYAML全体をパースしてJSONに変換
return yaml.parse(text);
};
Expand Down

0 comments on commit 76bb549

Please sign in to comment.