Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/with added pagination #189

Merged
merged 19 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6b5d3a1
fix: renamed production-list to production-list-container and separat…
malmen237 Jun 28, 2024
bc0f07e
fix: updated component name
malmen237 Jun 28, 2024
6fa2755
feat: re-usable production-list-component
malmen237 Jun 28, 2024
35083b2
feat: added list of productions and a show-list-btn, rearranged some …
malmen237 Jun 28, 2024
30ee8b2
fix: updated global state-name to be suitable for both create and del…
malmen237 Jul 9, 2024
9813430
fix: made reload-prop optional
malmen237 Jul 9, 2024
4b8e468
feat: added a save-state for entire production-list
malmen237 Jul 9, 2024
72168f8
fix: added margin for better mobile-view
malmen237 Jul 9, 2024
ccf9d07
fix: added margin for better mobile-view
malmen237 Jul 9, 2024
1d5c88f
feat: adjusted mobile-view, added loader and update-list, changed lay…
malmen237 Jul 9, 2024
0dbd3f2
feat: updated to new fetch-endpoint with search-params
malmen237 Jul 9, 2024
2ebab27
feat: added icons for stepping left and right
malmen237 Jul 9, 2024
bfb59d6
feat: added a paginated list-view to manage-prod-page
malmen237 Jul 9, 2024
6e5ac68
feat: updated fetch-hook with filters and added fetch-update
malmen237 Jul 9, 2024
05e0d70
feat: added cursor-pointer through optional-classname to list-items o…
malmen237 Jul 10, 2024
14f166c
fix: added limit-param to loading-page list and removed slice
malmen237 Jul 10, 2024
2df36f0
fix: removed duplicate new-search-params and made fetch to run on off…
malmen237 Jul 10, 2024
5b7f533
fix: removed interval-load use-effect triggered by updated offset
malmen237 Jul 10, 2024
ca044da
feat: added pages-array, added cursor-pointer to list and page-btns
malmen237 Jul 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ type TFetchProductionResponse = TBasicProductionResponse & {
lines: TLine[];
};

type TListProductionsResponse = TBasicProductionResponse[];
export type TListProductionsResponse = {
productions: TBasicProductionResponse[];
offset: 0;
limit: 0;
totalItems: 0;
};

type TOfferAudioSessionOptions = {
productionId: number;
Expand Down Expand Up @@ -77,9 +82,13 @@ export const API = {
}),
})
),
listProductions: (): Promise<TListProductionsResponse> =>
listProductions: ({
searchParams,
}: {
searchParams: string;
}): Promise<TListProductionsResponse> =>
handleFetchRequest<TListProductionsResponse>(
fetch(`${API_URL}production/`, {
fetch(`${API_URL}productionlist?${searchParams}`, {
method: "GET",
headers: {
...(API_KEY ? { Authorization: `Bearer ${API_KEY}` } : {}),
Expand Down
4 changes: 4 additions & 0 deletions src/assets/icons/chevron_left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/assets/icons/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import VolumeOn from "./volume_on.svg?react";
import VolumeOff from "./volume_off.svg?react";
import UserSvg from "./user.svg?react";
import ConfirmSvg from "./done.svg?react";
import StepLeftSvg from "./chevron_left.svg?react";
import StepRightSvg from "./navigate_next.svg?react";

export const MicMuted = () => <MicMute />;

Expand All @@ -22,3 +24,7 @@ export const SpeakerOn = () => <VolumeOn />;
export const UserIcon = () => <UserSvg />;

export const ConfirmIcon = () => <ConfirmSvg />;

export const StepLeftIcon = () => <StepLeftSvg />;

export const StepRightIcon = () => <StepRightSvg />;
4 changes: 4 additions & 0 deletions src/assets/icons/navigate_next.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/components/landing-page/create-production.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const CreateProduction = () => {
lines: [],
});
dispatch({
type: "PRODUCTION_CREATED",
type: "PRODUCTION_UPDATED",
});
}
}, [createdProductionId, dispatch, reset]);
Expand Down
4 changes: 2 additions & 2 deletions src/components/landing-page/landing-page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { JoinProduction } from "./join-production.tsx";
import { CreateProduction } from "./create-production.tsx";
import { ProductionsList } from "./productions-list.tsx";
import { ProductionsListContainer } from "./productions-list-container.tsx";
import { useNavigateToProduction } from "./use-navigate-to-production.ts";
import { DisplayContainer, FlexContainer } from "../generic-components.ts";
import { useGlobalState } from "../../global-state/context-provider.tsx";
Expand All @@ -23,7 +23,7 @@ export const LandingPage = () => {
</DisplayContainer>
)}
</FlexContainer>
<ProductionsList />
<ProductionsListContainer />
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,24 @@ import { useRefreshAnimation } from "./use-refresh-animation.ts";
import { DisplayContainerHeader } from "./display-container-header.tsx";
import { DisplayContainer } from "../generic-components.ts";
import { ManageProductionButton } from "./manage-production-button.tsx";
import { LocalError } from "../error.tsx";
import { useFetchProductionList } from "./use-fetch-production-list.ts";

const ProductionListContainer = styled.div`
display: flex;
padding: 0 0 2rem 2rem;
flex-wrap: wrap;
`;
import { ProductionsList } from "../productions-list.tsx";

const HeaderContainer = styled(DisplayContainer)`
padding: 0 2rem 0 2rem;
`;

const ProductionItem = styled.div`
flex: 1 0 calc(25% - 2rem);
min-width: 20rem;
border: 1px solid #424242;
border-radius: 0.5rem;
padding: 2rem;
margin: 0 2rem 2rem 0;
const LoaderWrapper = styled.div`
padding-bottom: 1rem;
`;

const ProductionName = styled.div`
font-size: 1.4rem;
font-weight: bold;
margin: 0 0 1rem;
word-break: break-word;
`;

const ProductionId = styled.div`
font-size: 2rem;
color: #9e9e9e;
const ListWrapper = styled.div`
display: flex;
flex-wrap: wrap;
padding: 0 0 0 2rem;
`;

export const ProductionsList = () => {
export const ProductionsListContainer = () => {
const [{ reloadProductionList }] = useGlobalState();

const { productions, doInitialLoad, error, setIntervalLoad } =
Expand All @@ -63,24 +46,22 @@ export const ProductionsList = () => {

return (
<>
<LoaderDots
className={showRefreshing ? "active" : "in-active"}
text="refreshing"
/>
<LoaderWrapper>
<LoaderDots
className={showRefreshing ? "active" : "in-active"}
text="refreshing"
/>
</LoaderWrapper>
<HeaderContainer>
<DisplayContainerHeader>Production List</DisplayContainerHeader>
</HeaderContainer>
<ProductionListContainer>
{error && <LocalError error={error} />}
{!error &&
productions.map((p) => (
<ProductionItem key={p.productionId}>
<ProductionName>{p.name}</ProductionName>
<ProductionId>{p.productionId}</ProductionId>
</ProductionItem>
))}
</ProductionListContainer>
{!!productions.length && <ManageProductionButton />}
<ListWrapper>
<ProductionsList
productions={productions?.productions.slice(0, 10)}
malmen237 marked this conversation as resolved.
Show resolved Hide resolved
error={error}
/>
</ListWrapper>
{!!productions?.productions.length && <ManageProductionButton />}
</>
);
};
26 changes: 15 additions & 11 deletions src/components/landing-page/use-fetch-production-list.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { useEffect, useState } from "react";
import { useGlobalState } from "../../global-state/context-provider";
import { API } from "../../api/api.ts";
import { TBasicProduction } from "../production-line/types.ts";
import { API, TListProductionsResponse } from "../../api/api.ts";

export const useFetchProductionList = () => {
const [productions, setProductions] = useState<TBasicProduction[]>([]);
export type GetProductionListFilter = {
limit?: string;
offset?: string;
};

export const useFetchProductionList = (filter?: GetProductionListFilter) => {
const [productions, setProductions] = useState<TListProductionsResponse>();
const [doInitialLoad, setDoInitialLoad] = useState(true);
const [intervalLoad, setIntervalLoad] = useState<boolean>(false);
const [error, setError] = useState<Error | null>(null);
Expand All @@ -15,15 +19,15 @@ export const useFetchProductionList = () => {
let aborted = false;

if (reloadProductionList || intervalLoad || doInitialLoad) {
API.listProductions()
const filterSearchParams = new URLSearchParams(filter);

const searchParams = new URLSearchParams(filterSearchParams).toString();
malmen237 marked this conversation as resolved.
Show resolved Hide resolved

API.listProductions({ searchParams })
.then((result) => {
if (aborted) return;

setProductions(
result
// pick last 10 items and display newest first
.slice(0, 10)
);
setProductions(result);

dispatch({
type: "PRODUCTION_LIST_FETCHED",
Expand All @@ -45,7 +49,7 @@ export const useFetchProductionList = () => {
return () => {
aborted = true;
};
}, [dispatch, intervalLoad, reloadProductionList, doInitialLoad]);
}, [dispatch, intervalLoad, reloadProductionList, doInitialLoad, filter]);

return {
productions,
Expand Down
2 changes: 1 addition & 1 deletion src/components/landing-page/use-refresh-animation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from "react";

type TUseRefreshAnimationOptions = {
reloadProductionList: boolean;
reloadProductionList?: boolean;
doInitialLoad: boolean;
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/manage-productions/manage-lines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Container = styled.div`
max-width: 45rem;
min-width: 35rem;
padding: 2rem;
margin-right: 2rem;
margin: 0 2rem 2rem 0;
border-radius: 1rem;
border: 0.2rem solid #434343;
`;
Expand Down
Loading
Loading