Skip to content

Commit

Permalink
Merge pull request #99 from maykinmedia/fix/75-landing-page-403
Browse files Browse the repository at this point in the history
[#75] Add redirect to log in if user not logged in
  • Loading branch information
SilviaAmAm authored Jun 7, 2024
2 parents e8d4af3 + 33472ca commit 6228ea5
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions frontend/src/pages/landing/Landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
DestructionList,
listDestructionLists,
} from "../../lib/api/destructionLists";
import { loginRequired } from "../../lib/api/loginRequired";
import { timeAgo } from "../../lib/string";
import "./Landing.css";

Expand Down Expand Up @@ -43,20 +44,22 @@ interface LandingLoaderReturn {
[key: string]: DestructionList[];
}

export const landingLoader = async (): Promise<LandingLoaderReturn> => {
const lists = await listDestructionLists();
export const landingLoader = loginRequired(
async (): Promise<LandingLoaderReturn> => {
const lists = await listDestructionLists();

// Initialize statusMap with empty arrays for each status
const statusMap = STATUSES.reduce((acc, val) => {
const status = val[0] || "";
const destructionLists = lists.filter(
(l) => STATUS_LABELS[l.status] === status,
);
return { ...acc, [status]: destructionLists };
}, {});
// Initialize statusMap with empty arrays for each status
const statusMap = STATUSES.reduce((acc, val) => {
const status = val[0] || "";
const destructionLists = lists.filter(
(l) => STATUS_LABELS[l.status] === status,
);
return { ...acc, [status]: destructionLists };
}, {});

return statusMap;
};
return statusMap;
},
);

export const Landing = () => {
const lists = useLoaderData() as LandingLoaderReturn;
Expand Down

0 comments on commit 6228ea5

Please sign in to comment.