Skip to content

Commit

Permalink
update pinned ui. remove paging if dashboard edited
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscao633 committed Nov 19, 2024
1 parent 2729538 commit ec2f520
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
5 changes: 0 additions & 5 deletions src/app/(main)/dashboard/DashboardEdit.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
padding: 5px;
}

.pin {
width: 20px;
height: 20px;
}

.item h1 {
font-weight: 600;
font-size: 16px;
Expand Down
23 changes: 17 additions & 6 deletions src/app/(main)/dashboard/DashboardEdit.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState, useMemo, useEffect } from 'react';
import { DragDropContext, Draggable, Droppable } from 'react-beautiful-dnd';
import classNames from 'classnames';
import { Button, Loading } from 'react-basics';
import { Button, Icon, Loading } from 'react-basics';
import Icons from 'components/icons';
import { firstBy } from 'thenby';
import useDashboard, { saveDashboard } from 'store/dashboard';
Expand All @@ -12,10 +12,11 @@ const DRAG_ID = 'dashboard-website-ordering';

export function DashboardEdit({ teamId }: { teamId: string }) {
const settings = useDashboard();
const { websiteOrder, websiteActive } = settings;
const { websiteOrder, websiteActive, isEdited } = settings;
const { formatMessage, labels } = useMessages();
const [order, setOrder] = useState(websiteOrder || []);
const [active, setActive] = useState(websiteActive || []);
const [edited, setEdited] = useState(isEdited);
const [websites, setWebsites] = useState([]);

const {
Expand All @@ -39,7 +40,10 @@ export function DashboardEdit({ teamId }: { teamId: string }) {
const ordered = useMemo(() => {
if (websites) {
return websites
.map((website: { id: any }) => ({ ...website, order: order.indexOf(website.id) }))
.map((website: { id: any; name: string; domain: string }) => ({
...website,
order: order.indexOf(website.id),
}))
.sort(firstBy('order'));
}
return [];
Expand All @@ -53,29 +57,33 @@ export function DashboardEdit({ teamId }: { teamId: string }) {
orderedWebsites.splice(destination.index, 0, removed);

setOrder(orderedWebsites.map(website => website?.id || 0));
setEdited(true);
}

function handleActiveWebsites(id: string) {
setActive(prevActive =>
prevActive.includes(id) ? prevActive.filter(a => a !== id) : [...prevActive, id],
);
setEdited(true);
}

function handleSave() {
saveDashboard({
editing: false,
isEdited: edited,
websiteOrder: order,
websiteActive: active,
});
}

function handleCancel() {
saveDashboard({ editing: false, websiteOrder, websiteActive });
saveDashboard({ editing: false, websiteOrder, websiteActive, isEdited });
}

function handleReset() {
setOrder([]);
setActive([]);
setEdited(false);
}

if (isLoading) {
Expand Down Expand Up @@ -115,11 +123,14 @@ export function DashboardEdit({ teamId }: { teamId: string }) {
})}
{...provided.draggableProps}
{...provided.dragHandleProps}
onClick={() => handleActiveWebsites(id)}
>
<div className={styles.text}>
<div className={styles.pinActive}>
{active.includes(id) ? <Icons.PushPin className={styles.pin} /> : null}
<Button size="sm" onClick={() => handleActiveWebsites(id)}>
<Icon rotate={active.includes(id) ? 0 : 45}>
<Icons.PushPin />
</Icon>
</Button>
</div>
<h1>{name}</h1>
<h2>{domain}</h2>
Expand Down
4 changes: 2 additions & 2 deletions src/app/(main)/dashboard/DashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import LinkButton from 'components/common/LinkButton';
export function DashboardPage() {
const { formatMessage, labels, messages } = useMessages();
const { teamId, renderTeamUrl } = useTeamUrl();
const { showCharts, editing } = useDashboard();
const { showCharts, editing, isEdited } = useDashboard();
const { dir } = useLocale();
const pageSize = 10;
const pageSize = isEdited ? 200 : 10;

const { result, query, params, setParams } = useWebsites({ teamId }, { pageSize });
const { page } = params;
Expand Down
1 change: 1 addition & 0 deletions src/store/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const initialState = {
websiteOrder: [],
websiteActive: [],
editing: false,
isEdited: false,
};

const store = create(() => ({ ...initialState, ...getItem(DASHBOARD_CONFIG) }));
Expand Down

0 comments on commit ec2f520

Please sign in to comment.