Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
reearth-app[bot] committed Aug 9, 2024
2 parents 8e2888e + b46698f commit 622138e
Show file tree
Hide file tree
Showing 22 changed files with 848 additions and 438 deletions.
5 changes: 5 additions & 0 deletions web/src/beta/components/Icon/Icons/linkStoryBlockButton.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions web/src/beta/components/Icon/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ import ShowLayersStoryBlock from "./Icons/showLayersStoryBlock.svg?react";
import TimelineStoryBlock from "./Icons/timelineStoryBlock.svg?react";
import TimelineStoryBlockSolid from "./Icons/timelineStoryBlockSolid.svg?react";
import NextPageStoryBlock from "./Icons/nextPageStoryBlock.svg?react";
//TODO: will be not be use in future
import LinkButtonStoryBlock from "./Icons/linkStoryBlockButton.svg?react";

// Widget tab
import Desktop from "./Icons/desktop.svg?react";
Expand Down Expand Up @@ -204,6 +206,7 @@ export default {
timelineStoryBlock: TimelineStoryBlock,
timelineStoryBlockSolid: TimelineStoryBlockSolid,
nextPageStoryBlock: NextPageStoryBlock,
linkButtonStoryBlock: LinkButtonStoryBlock,
widget: Widgets,
widgets: Widgets,
menu: WidgetMenu,
Expand Down
22 changes: 11 additions & 11 deletions web/src/beta/features/Assets/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import { useCallback, useState, useRef, useMemo, useEffect } from "react";
import { Asset, SortType } from "@reearth/beta/features/Assets/types";
import { autoFillPage, onScrollToBottom } from "@reearth/beta/utils/infinite-scroll";
import { useAssetsFetcher } from "@reearth/services/api";
import { Maybe, AssetSortType as GQLSortType } from "@reearth/services/gql";
import { Maybe } from "@reearth/services/gql";
import { useT } from "@reearth/services/i18n";

// TODO: Remove this file

const assetsPerPage = 20;

const enumTypeMapper: Partial<Record<GQLSortType, string>> = {
[GQLSortType.Date]: "date",
[GQLSortType.Name]: "name",
[GQLSortType.Size]: "size",
};
// const enumTypeMapper: Partial<Record<GQLSortType, string>> = {
// [GQLSortType.Date]: "date",
// [GQLSortType.Name]: "name",
// [GQLSortType.Size]: "size",
// };

function toGQLEnum(val?: SortType) {
if (!val) return;
return (Object.keys(enumTypeMapper) as GQLSortType[]).find(k => enumTypeMapper[k] === val);
}
// function toGQLEnum(val?: SortType) {
// if (!val) return;
// return (Object.keys(enumTypeMapper) as GQLSortType[]).find(k => enumTypeMapper[k] === val);
// }

function pagination(
sort?: { type?: Maybe<SortType>; reverse?: boolean },
Expand Down Expand Up @@ -55,7 +55,7 @@ export default ({
const { assets, hasMoreAssets, loading, isRefetching, endCursor, fetchMore } = useAssetsQuery({
teamId: workspaceId ?? "",
pagination: pagination(sort),
sort: toGQLEnum(sort?.type),
// sort: toGQLEnum(sort?.type),
keyword: searchTerm,
});

Expand Down
49 changes: 19 additions & 30 deletions web/src/beta/features/AssetsManager/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import useFileInput from "use-file-input";
import { BreadcrumbItem } from "@reearth/beta/lib/reearth-ui";
import { ManagerLayout } from "@reearth/beta/ui/components/ManagerBase";
import { useAssetsFetcher } from "@reearth/services/api";
import { AssetSortType, Maybe } from "@reearth/services/gql";
import { AssetSortField, SortDirection } from "@reearth/services/gql";
import { useT } from "@reearth/services/i18n";

import {
Expand All @@ -18,6 +18,12 @@ import { Asset, sortOptionValue, SortType } from "./types";
const ASSETS_PER_PAGE = 20;
const ASSETS_LAYOUT_STORAGE_KEY = `reearth-visualizer-dashboard-assets-layout`;

const typeToGQLField = {
date: AssetSortField.Date,
name: AssetSortField.Name,
size: AssetSortField.Size,
};

export default ({
workspaceId,
allowMultipleSelection,
Expand Down Expand Up @@ -96,8 +102,13 @@ export default ({
const { useAssetsQuery, useRemoveAssets, useCreateAssets } = useAssetsFetcher();
const { assets, hasMoreAssets, isRefetching, endCursor, loading, fetchMore } = useAssetsQuery({
teamId: workspaceId ?? "",
pagination: pagination(sort),
sort: toGQLEnum(sort?.type),
pagination: {
first: ASSETS_PER_PAGE,
},
sort: {
direction: sort.reverse ? SortDirection.Desc : SortDirection.Asc,
field: typeToGQLField[sort.type ?? "date"],
},
keyword: searchTerm,
});

Expand Down Expand Up @@ -125,12 +136,15 @@ export default ({
setLoadingMore(true);
await fetchMore({
variables: {
pagination: pagination(sort, endCursor),
pagination: {
first: ASSETS_PER_PAGE,
after: endCursor,
},
},
});
setLoadingMore(false);
isLoadingMoreRef.current = false;
}, [hasMoreAssets, isRefetching, fetchMore, sort, endCursor]);
}, [hasMoreAssets, isRefetching, fetchMore, endCursor]);

const loadMoreRef = useRef<() => void>(loadMore);
loadMoreRef.current = loadMore;
Expand Down Expand Up @@ -309,28 +323,3 @@ export default ({
loadingMore,
};
};

const enumTypeMapper: Partial<Record<AssetSortType, string>> = {
[AssetSortType.Date]: "date",
[AssetSortType.Name]: "name",
[AssetSortType.Size]: "size",
};

function toGQLEnum(val?: SortType) {
if (!val) return;
return (Object.keys(enumTypeMapper) as AssetSortType[]).find(k => enumTypeMapper[k] === val);
}

function pagination(
sort?: { type?: Maybe<SortType>; reverse?: boolean },
endCursor?: string | null,
) {
const reverseOrder = !sort?.type || sort?.type === "date" ? !sort?.reverse : !!sort?.reverse;

return {
after: !reverseOrder ? endCursor : undefined,
before: reverseOrder ? endCursor : undefined,
first: !reverseOrder ? ASSETS_PER_PAGE : undefined,
last: reverseOrder ? ASSETS_PER_PAGE : undefined,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ export default (workspaceId?: string) => {
const navigate = useNavigate();

const [searchTerm, setSearchTerm] = useState<string>();
const [sortValue, setSort] = useState<SortType>("date");
const [sortValue, setSort] = useState<SortType>("date-updated");

const wrapperRef = useRef<HTMLDivElement>(null);

const { projects, loading, isRefetching, hasMoreProjects, endCursor, fetchMore } =
useProjectsQuery({
teamId: workspaceId || "",
first: pagination(sortValue).first,
last: pagination(sortValue).last,
pagination: {
first: pagination(sortValue).first,
},
sort: pagination(sortValue).sortBy,
keyword: searchTerm,
});
Expand Down Expand Up @@ -68,8 +69,10 @@ export default (workspaceId?: string) => {
isFetchingMore.current = true;
await fetchMore({
variables: {
after: endCursor,
first: PROJECTS_PER_PAGE,
pagination: {
after: endCursor,
first: PROJECTS_PER_PAGE,
},
},
});
isFetchingMore.current = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,11 @@ const Projects: FC<{ workspaceId?: string }> = ({ workspaceId }) => {
</FlexTableBody>
</FlexTable>
)}
{isLoading &&
(hasMoreProjects ? (
<StyledLoading>
<Loading relative />
</StyledLoading>
) : (
{isLoading && (
<LoadingWrapper>
<Loading relative />
))}
</LoadingWrapper>
)}
</ProjectsWrapper>
{projectCreatorVisible && (
<ProjectCreatorModal
Expand Down Expand Up @@ -327,6 +324,7 @@ const TimeCell = styled("div")(() => ({
flex: 0.5,
}));

const StyledLoading = styled("div")(() => ({
margin: "52px auto",
const LoadingWrapper = styled("div")(() => ({
width: "100%",
height: 100,
}));
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,15 @@ const ButtonWrapper = styled("div")(({ theme }) => ({
maxWidth: "400px",
}));

const StyledButton = styled(Button)<{ color?: string; bgColor?: string }>(({ color, bgColor }) => ({
color: color || color,
background: bgColor || bgColor,
borderColor: color || color,
["&:hover"]: {
color: bgColor || bgColor,
background: color ? color : "inherit",
},
}));
const StyledButton = styled(Button)<{ color?: string; bgColor?: string; userSelected?: boolean }>(
({ color, bgColor, userSelected, theme }) => ({
color: userSelected ? bgColor ?? theme.content.strong : color,
backgroundColor: userSelected ? color ?? theme.primary.main : bgColor,
borderColor: color,

":hover": {
color: bgColor,
backgroundColor: color ?? theme.primary.main,
},
}),
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import { FC, useCallback, useContext, useState } from "react";

import Button from "@reearth/beta/components/Button";
import { BlockContext } from "@reearth/beta/features/Visualizer/shared/components/BlockWrapper";
import { useT } from "@reearth/services/i18n";
import { styled } from "@reearth/services/theme";

import LinkEditor, { type LinkBlock as LinkBlockType } from "./Editor";

type Props = {
propertyId?: string;
linkButtons: LinkBlockType[];
isEditable?: boolean;
onPropertyUpdate?: (
propertyId?: string,
schemaItemId?: string,
fieldId?: string,
itemId?: string,
vt?: any,
v?: any,
) => Promise<void>;
onPropertyItemAdd?: (propertyId?: string, schemaGroupId?: string) => Promise<void>;
onPropertyItemMove?: (
propertyId?: string,
schemaGroupId?: string,
itemId?: string,
index?: number,
) => Promise<void>;
onPropertyItemDelete?: (
propertyId?: string,
schemaGroupId?: string,
itemId?: string,
) => Promise<void>;
};

const Content: FC<Props> = ({
propertyId,
linkButtons,
isEditable,
onPropertyUpdate,
onPropertyItemAdd,
onPropertyItemDelete,
onPropertyItemMove,
}) => {
const t = useT();
const blockContext = useContext(BlockContext);
const [selected, setSelected] = useState<string>(linkButtons[0]?.id);

const handleClick = useCallback(
(itemId: string) => {
if (isEditable) {
setSelected(itemId);
return;
}
const item = linkButtons.find(i => i.id === itemId);

if (!item?.url?.value) return;
window.open(item.url.value, "_blank");
},
[isEditable, linkButtons],
);

return (
<Wrapper>
<ButtonWrapper>
{linkButtons.map(({ title, color, bgColor, id }) => {
return (
//The button will be updated in future
<StyledButton
key={id}
color={color?.value}
bgColor={bgColor?.value}
icon="linkButtonStoryBlock"
buttonType="primary"
text={title?.value ?? t("New Link Button")}
size="small"
onClick={() => handleClick(id)}
/>
);
})}
</ButtonWrapper>
{blockContext?.editMode && (
<LinkEditor
items={linkButtons}
propertyId={propertyId}
selected={selected}
setSelected={setSelected}
onPropertyUpdate={onPropertyUpdate}
onPropertyItemAdd={onPropertyItemAdd}
onPropertyItemMove={onPropertyItemMove}
onPropertyItemDelete={onPropertyItemDelete}
/>
)}
</Wrapper>
);
};

export default Content;

const Wrapper = styled("div")(() => ({
width: "100%",
}));

const ButtonWrapper = styled("div")(({ theme }) => ({
width: "100%",
display: "flex",
flexWrap: "wrap",
gap: theme.spacing.smallest,
maxWidth: "400px",
}));

const StyledButton = styled(Button)<{ color?: string; bgColor?: string; userSelected?: boolean }>(
({ color, bgColor, userSelected, theme }) => ({
color: userSelected ? bgColor ?? theme.content.strong : color,
backgroundColor: userSelected ? color ?? theme.primary.main : bgColor,
borderColor: color,

":hover": {
color: bgColor,
backgroundColor: color ?? theme.primary.main,
},
}),
);
Loading

0 comments on commit 622138e

Please sign in to comment.