working on search page
This commit is contained in:
34
src/App.js
34
src/App.js
@@ -21,6 +21,7 @@ import Footer from "./components/Footer";
|
|||||||
|
|
||||||
import GuestSideLogin from "./pages/GuestSideLogin";
|
import GuestSideLogin from "./pages/GuestSideLogin";
|
||||||
import GuestSide from "./pages/GuestSide";
|
import GuestSide from "./pages/GuestSide";
|
||||||
|
import { getItemTypesWithItems } from "./helpers/itemHelper.js";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
// checkToken,
|
// checkToken,
|
||||||
@@ -41,6 +42,7 @@ function App() {
|
|||||||
const [shopId, setShopId] = useState("");
|
const [shopId, setShopId] = useState("");
|
||||||
const [totalItemsCount, setTotalItemsCount] = useState(0);
|
const [totalItemsCount, setTotalItemsCount] = useState(0);
|
||||||
const [deviceType, setDeviceType] = useState("");
|
const [deviceType, setDeviceType] = useState("");
|
||||||
|
const [shopItems, setShopItems] = useState([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Function to calculate totals from localStorage
|
// Function to calculate totals from localStorage
|
||||||
@@ -71,6 +73,36 @@ function App() {
|
|||||||
setShopId(param);
|
setShopId(param);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function fetchData() {
|
||||||
|
try {
|
||||||
|
const { response, data } = await getItemTypesWithItems(shopId);
|
||||||
|
console.log(data);
|
||||||
|
if (response.status === 200) {
|
||||||
|
setShopItems(data);
|
||||||
|
console.log(data);
|
||||||
|
// setLoading(false);
|
||||||
|
socket.emit("join-room", { token: getLocalStorage("auth"), shopId });
|
||||||
|
|
||||||
|
socket.on("joined-room", (response) => {
|
||||||
|
// const { isSpotifyNeedLogin } = response;
|
||||||
|
// setNeedSpotifyLogin(isSpotifyNeedLogin);
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on("transaction_created", () => {
|
||||||
|
console.log("transaction created");
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// setScreenMessage("Kafe tidak tersedia");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching shop items:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shopId != "") fetchData();
|
||||||
|
}, [shopId]);
|
||||||
|
|
||||||
const rmConnectedGuestSides = async (gueseSideSessionId) => {
|
const rmConnectedGuestSides = async (gueseSideSessionId) => {
|
||||||
const sessionLeft = await removeConnectedGuestSides(gueseSideSessionId);
|
const sessionLeft = await removeConnectedGuestSides(gueseSideSessionId);
|
||||||
setGuestSides(sessionLeft.guestSideList);
|
setGuestSides(sessionLeft.guestSideList);
|
||||||
@@ -182,6 +214,7 @@ function App() {
|
|||||||
<>
|
<>
|
||||||
<CafePage
|
<CafePage
|
||||||
sendParam={handleSetParam}
|
sendParam={handleSetParam}
|
||||||
|
shopItems={shopItems}
|
||||||
socket={socket}
|
socket={socket}
|
||||||
user={user} // if logged
|
user={user} // if logged
|
||||||
guestSides={guestSides} // if being clerk
|
guestSides={guestSides} // if being clerk
|
||||||
@@ -202,6 +235,7 @@ function App() {
|
|||||||
<>
|
<>
|
||||||
<SearchResult
|
<SearchResult
|
||||||
user={user} // if logged
|
user={user} // if logged
|
||||||
|
shopItems={shopItems}
|
||||||
guestSides={guestSides} // if being clerk
|
guestSides={guestSides} // if being clerk
|
||||||
guestSideOfClerk={guestSideOfClerk} // if being guest side
|
guestSideOfClerk={guestSideOfClerk} // if being guest side
|
||||||
removeConnectedGuestSides={(e) => rmConnectedGuestSides(e)}
|
removeConnectedGuestSides={(e) => rmConnectedGuestSides(e)}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ const SearchIcon = styled.svg`
|
|||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default function SearchInput({ shopId, autofocus }) {
|
export default function SearchInput({ shopId, autofocus, onSearchChange }) {
|
||||||
const [songName, setSongName] = useState("");
|
const [songName, setSongName] = useState("");
|
||||||
const [debouncedSongName, setDebouncedSongName] = useState("");
|
const [debouncedSongName, setDebouncedSongName] = useState("");
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
@@ -78,6 +78,7 @@ export default function SearchInput({ shopId, autofocus }) {
|
|||||||
navigate(`/${shopId}`);
|
navigate(`/${shopId}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (onSearchChange) onSearchChange(songName);
|
||||||
}
|
}
|
||||||
}, [songName]);
|
}, [songName]);
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import {
|
|||||||
|
|
||||||
function CafePage({
|
function CafePage({
|
||||||
sendParam,
|
sendParam,
|
||||||
|
shopItems,
|
||||||
socket,
|
socket,
|
||||||
user,
|
user,
|
||||||
guestSides,
|
guestSides,
|
||||||
@@ -36,8 +37,6 @@ function CafePage({
|
|||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [screenMessage, setScreenMessage] = useState("");
|
const [screenMessage, setScreenMessage] = useState("");
|
||||||
|
|
||||||
const [shopItems, setShopItems] = useState([]);
|
|
||||||
|
|
||||||
const [isSpotifyNeedLogin, setNeedSpotifyLogin] = useState(false);
|
const [isSpotifyNeedLogin, setNeedSpotifyLogin] = useState(false);
|
||||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||||
|
|
||||||
@@ -65,35 +64,8 @@ function CafePage({
|
|||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchData() {
|
setLoading(false);
|
||||||
try {
|
}, [shopItems]);
|
||||||
setLoading(true);
|
|
||||||
const { response, data } = await getItemTypesWithItems(shopId);
|
|
||||||
console.log(data);
|
|
||||||
if (response.status === 200) {
|
|
||||||
setShopItems(data);
|
|
||||||
setLoading(false);
|
|
||||||
socket.emit("join-room", { token: getLocalStorage("auth"), shopId });
|
|
||||||
|
|
||||||
socket.on("joined-room", (response) => {
|
|
||||||
const { isSpotifyNeedLogin } = response;
|
|
||||||
setNeedSpotifyLogin(isSpotifyNeedLogin);
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on("transaction_created", () => {
|
|
||||||
console.log("transaction created");
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
setScreenMessage("Kafe tidak tersedia");
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error fetching shop items:", error);
|
|
||||||
setLoading(false); // Ensure loading state is turned off on error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fetchData();
|
|
||||||
}, [shopId]);
|
|
||||||
|
|
||||||
if (loading)
|
if (loading)
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,46 +1,53 @@
|
|||||||
// src/CafePage.js
|
// src/CafePage.js
|
||||||
|
import React, { useState } from "react";
|
||||||
import React, { useState, useEffect } from "react";
|
import { useParams, useSearchParams } from "react-router-dom";
|
||||||
import { useParams, useSearchParams, useNavigate } from "react-router-dom";
|
|
||||||
|
|
||||||
import "../App.css";
|
import "../App.css";
|
||||||
import SearchInput from "../components/SearchInput";
|
import SearchInput from "../components/SearchInput";
|
||||||
import ItemLister from "../components/ItemLister";
|
import ItemLister from "../components/ItemLister";
|
||||||
import Header from "../components/Header";
|
import Header from "../components/Header";
|
||||||
|
|
||||||
import { ThreeDots } from "react-loader-spinner";
|
function SearchResult({ user, shopItems }) {
|
||||||
|
|
||||||
import { getItemTypesWithItems } from "../helpers/itemHelper.js";
|
|
||||||
import {
|
|
||||||
getLocalStorage,
|
|
||||||
updateLocalStorage,
|
|
||||||
} from "../helpers/localStorageHelpers";
|
|
||||||
|
|
||||||
function SearchResult({ user }) {
|
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const { shopId } = useParams();
|
const { shopId } = useParams();
|
||||||
|
const [searchValue, setSearchValue] = useState(
|
||||||
|
"dwadawa vvwqd21qb13 4kfawfdwa dhawldhawr dliawbdjawndlks",
|
||||||
|
);
|
||||||
|
|
||||||
const handleLogout = () => {
|
// Function to handle search input change
|
||||||
updateLocalStorage("auth", "");
|
const handleSearchChange = (value) => {
|
||||||
|
setSearchValue(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const filteredItems = shopItems
|
||||||
|
.map((itemType) => {
|
||||||
|
// Filter items in the itemList based on searchValue
|
||||||
|
const filteredItemList = itemType.itemList.filter((item) =>
|
||||||
|
item.name.toLowerCase().includes(searchValue.toLowerCase()),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Return itemType with only filtered items
|
||||||
|
return {
|
||||||
|
...itemType,
|
||||||
|
itemList: filteredItemList,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.filter((itemType) => itemType.itemList.length > 0); // Only include itemTypes with matching items
|
||||||
|
|
||||||
|
console.log(filteredItems);
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
<body className="App-header">
|
<header className="App-header">
|
||||||
<Header HeaderText={"Search"} shopId={shopId} user={user} />
|
<Header HeaderText={"Search"} shopId={shopId} user={user} />
|
||||||
<div style={{ marginTop: "5px" }}></div>
|
<div style={{ marginTop: "5px" }}></div>
|
||||||
<SearchInput shopId={shopId} autofocus={true} />
|
<SearchInput
|
||||||
<div style={{ marginTop: "15px" }}></div>
|
|
||||||
{/* <ItemTypeLister user={user} shopId={shopId} itemTypes={shopItems} /> */}
|
|
||||||
<div style={{ marginTop: "-13px" }}></div>
|
|
||||||
{/* <MusicPlayer
|
|
||||||
socket={socket}
|
|
||||||
shopId={shopId}
|
shopId={shopId}
|
||||||
user={user}
|
autofocus={true}
|
||||||
isSpotifyNeedLogin={isSpotifyNeedLogin}
|
onSearchChange={handleSearchChange}
|
||||||
/>
|
/>
|
||||||
<div style={{ marginTop: "-15px" }}></div>
|
<div style={{ marginTop: "15px" }}></div>
|
||||||
{shopItems.map((itemType) => (
|
<div style={{ marginTop: "-13px" }}></div>
|
||||||
|
{filteredItems.map((itemType) => (
|
||||||
<ItemLister
|
<ItemLister
|
||||||
shopId={shopId}
|
shopId={shopId}
|
||||||
user={user}
|
user={user}
|
||||||
@@ -49,8 +56,8 @@ function SearchResult({ user }) {
|
|||||||
typeName={itemType.name}
|
typeName={itemType.name}
|
||||||
itemList={itemType.itemList}
|
itemList={itemType.itemList}
|
||||||
/>
|
/>
|
||||||
))} */}
|
))}
|
||||||
</body>
|
</header>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user