MCPcopy Index your code
hub / github.com/Packstack-Tech/packstack / Pack

Function Pack

frontend/src/app/Pack/Pack.tsx:25–125  ·  view source on GitHub ↗
({ getPack, weightUnit, packId })

Source from the content-addressed store, hash-verified

23import { Credit, PackWrapper, SectionHeader, SectionTitle, TripDescription, ItemsFooter } from "./styles";
24
25const Pack: React.FC<PackSpecs.Props> = ({ getPack, weightUnit, packId }) => {
26 const [loading, setLoading] = React.useState<boolean>(true);
27 const [pack, setPack] = React.useState<PackType | null>(null);
28 const [unit, setUnit] = React.useState<WeightUnit>(weightUnit);
29 const { dispatch } = useSidebar();
30 const app = React.useContext(AppContext);
31
32 React.useEffect(() => {
33 getPack(packId)
34 .then(pack => {
35 setPack(pack);
36 setLoading(false);
37 })
38 .catch(() => {
39 alertError({ message: 'Unable to retrieve pack.' });
40 });
41
42 return function cleanup() {
43 dispatch({ type: 'reset' });
44 }
45 }, []);
46
47 // render sidebar
48 React.useEffect(() => {
49 if (pack) {
50 const catWeights = getWeightByCategory(unit, pack.items);
51 const Sidebar = () => (
52 <>
53 <Statistics pack={pack}/>
54 <CategoryTable data={catWeights} unit={unit}/>
55 <CategoryChart data={catWeights}/>
56 </>
57 );
58
59 dispatch({ type: 'setTitle', value: 'Details' });
60 dispatch({ type: 'setContent', value: Sidebar() })
61 }
62 }, [pack, unit]);
63
64 const componentDecorator = (href: string, text: string, key: number | string) => (
65 <a href={href} key={key} target="_blank">{text}</a>
66 );
67
68 if (loading) {
69 return <Loading size="large"/>
70 }
71
72 if (!pack) {
73 return <p>Pack not found!</p>
74 }
75
76 const userPack = app.userInfo && app.userInfo.id === pack.userId;
77 const isEditable = () => userPack && (
78 <div className="edit-link">
79 <Link to={`/pack/${pack.id}`}>Edit</Link>
80 </div>
81 );
82

Callers

nothing calls this directly

Calls 5

useSidebarFunction · 0.90
alertErrorFunction · 0.90
getWeightByCategoryFunction · 0.90
isEditableFunction · 0.85
SidebarFunction · 0.70

Tested by

no test coverage detected