Skip to content

Commit

Permalink
Merge pull request #56 from MurakawaTakuya/fix/55-fix-PostForm
Browse files Browse the repository at this point in the history
PostFormの不要なファイル削除と修正
  • Loading branch information
MurakawaTakuya authored Nov 28, 2024
2 parents 32ab2fb + e52794a commit 66ffc09
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 42 deletions.
5 changes: 4 additions & 1 deletion functions/src/routers/postRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,14 @@ router.post("/", async (req: Request, res: Response) => {
return res.status(400).json({ message: "Invalid request body", error });
}

if (!userId || !storeId || !text || !goalId) {
if (!userId || !storeId || !goalId) {
return res
.status(400)
.json({ message: "userId, storeId, text, and goalId are required" });
}
if (!text) {
text = "";
}

try {
await db.collection("post").doc(postId).set({
Expand Down
18 changes: 11 additions & 7 deletions src/app/Components/GoalModal/GoalModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ export default function GoalModal() {

// 以下のJoy UIによるエラーを無効化
// Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release. Error Component Stack
const consoleError = console.error;
console.error = (...args) => {
if (args[0]?.includes("Accessing element.ref was removed")) {
return;
}
consoleError(...args);
};
try {
const consoleError = console.error;
console.error = (...args) => {
if (args[0]?.includes("Accessing element.ref was removed")) {
return;
}
consoleError(...args);
};
} catch {
console.error("Failed to disable Joy UI error");
}

return (
<>
Expand Down
20 changes: 4 additions & 16 deletions src/app/Components/PostForm/PostForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ export default function PostForm() {
const [progress, setProgress] = useState<number>(100);

const handleImageChange = (event: ChangeEvent<HTMLInputElement>) => {
// TODO: 画像の更新
const selectedFile = event.target.files?.[0];
setImage(selectedFile || null);
setError("");
};

const handleTextChange = (event: ChangeEvent<HTMLInputElement>) => {
// TODO: テキストの更新
setText(event.target.value);
};

Expand All @@ -29,10 +27,6 @@ export default function PostForm() {
setError("ファイルが選択されていません");
return;
}
if (!text) {
setError("テキストが入力されていません");
return;
}

// アップロード開始
uploadImage(
Expand All @@ -46,7 +40,7 @@ export default function PostForm() {

const postData = {
userId: "temp", // authenticatorが準備できるまで仮で設定
storeId: `post/${hash}/image`,
storeId: url, // トークン管理ができるまではurlをそのまま管理
text: text,
goalId: "temp", // authenticatorが準備できるまで仮で設定
};
Expand Down Expand Up @@ -82,21 +76,15 @@ export default function PostForm() {
<Typography variant="h6">投稿内容を入力</Typography>
{error && <Typography color="error">{error}</Typography>}

{/* TODO: テキスト入力 */}
<input
type = "text"
type="text"
value={text}
onChange={handleTextChange}
placeholder = "投稿内容を入力して下さい"
placeholder="投稿内容を入力して下さい"
/>

{/* TODO: 画像選択 */}
<input
type="file"
onChange={handleImageChange}
/>
<input type="file" onChange={handleImageChange} />

{/* TODO: アップロードボタン */}
<button onClick={handleUpload}>Upload</button>

{progress !== 100 && <LinearProgressWithLabel value={progress} />}
Expand Down
11 changes: 0 additions & 11 deletions src/app/Components/PostForm/PostFormPage.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions src/app/Components/PostForm/Posts.module.scss

This file was deleted.

4 changes: 2 additions & 2 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import {
import Button from "@mui/material/Button";
import Goal from "./Components/Goal/Goal";
import GoalModal from "./Components/GoalModal/GoalModal";
import ImageUploader from "./Components/PostForm/PostForm";
import PostForm from "./Components/PostForm/PostForm";
import Posts from "./Components/Posts/Posts";
import UserForm from "./Components/UserForm/UserForm";

export default function Top() {
return (
<>
<Posts />
<ImageUploader />
<PostForm />
<UserForm />
<Goal></Goal>
<GoalModal />
Expand Down
2 changes: 1 addition & 1 deletion src/app/utils/Uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const uploadImage = (

// cryptoモジュールを使用してユニークなIDを生成
const uniqueId = crypto.randomUUID();
const storageRef = ref(storage, `post/${uniqueId}/image`);
const storageRef = ref(storage, `post/${uniqueId}`);
const uploadTask = uploadBytesResumable(storageRef, file);

uploadTask.on(
Expand Down
2 changes: 1 addition & 1 deletion storage.rules
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /post/{documentId}/image {
match /post/{documentId} {
allow read, write: if true;
}
}
Expand Down

0 comments on commit 66ffc09

Please sign in to comment.