Skip to content

Commit

Permalink
chore(web): fix assets not refetching (#852)
Browse files Browse the repository at this point in the history
  • Loading branch information
KaWaite committed Dec 4, 2023
1 parent 76b9961 commit 0b60ec5
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 10 deletions.
Expand Up @@ -31,5 +31,5 @@ export const Default: Story = (args: Props) => {
Default.args = {
label: "test",
selected: false,
key: "test",
keyValue: "test",
};
8 changes: 4 additions & 4 deletions web/src/beta/components/RadioGroup/RadioBox/index.tsx
Expand Up @@ -4,12 +4,12 @@ import { fonts, styled } from "@reearth/services/theme";

export type Props = {
selected?: boolean;
key: string;
onClick?: (value: string) => void;
keyValue: string;
label?: string;
onClick?: (value: string) => void;
};

const RadioBox: React.FC<Props> = ({ selected, key, label, onClick }: Props) => {
const RadioBox: React.FC<Props> = ({ selected, keyValue, label, onClick }: Props) => {
const handleRadioClick = useCallback(
(value: string) => {
onClick?.(value);
Expand All @@ -19,7 +19,7 @@ const RadioBox: React.FC<Props> = ({ selected, key, label, onClick }: Props) =>

return (
<Radio>
<RadioInput type="radio" value={key} onClick={() => handleRadioClick(key)} />
<RadioInput type="radio" value={keyValue} onClick={() => handleRadioClick(keyValue)} />
<RadioButton selected={selected}>
{selected && <RadioIndicator selected={selected} />}
</RadioButton>
Expand Down
5 changes: 3 additions & 2 deletions web/src/beta/components/RadioGroup/index.tsx
Expand Up @@ -31,9 +31,10 @@ const RadioGroup: React.FC<RadioGroupProps> = ({

return (
<RadioGroupContainer layout={layout}>
{options.map(option => (
{options.map((option, idx) => (
<RadioBox
key={option.keyValue}
key={option.keyValue + idx}
keyValue={option.keyValue}
selected={option.keyValue === selectedValue}
label={option.label}
onClick={() => handleRadioChange(option.keyValue)}
Expand Down
10 changes: 10 additions & 0 deletions web/src/beta/features/Assets/hooks.ts
@@ -1,3 +1,4 @@
import { useApolloClient } from "@apollo/client";
import { useCallback, useState, useRef, useMemo, useEffect } from "react";

import { Asset, SortType } from "@reearth/beta/features/Assets/types";
Expand Down Expand Up @@ -39,6 +40,8 @@ export default ({
workspaceId?: string;
onAssetSelect?: (inputValue?: string) => void;
}) => {
const client = useApolloClient();

const [sort, setSort] = useState<{ type?: SortType; reverse?: boolean }>();
const [searchTerm, setSearchTerm] = useState<string>();
const [selectedAssets, selectAsset] = useState<Asset[]>([]);
Expand All @@ -54,6 +57,13 @@ export default ({
keyword: searchTerm,
});

useEffect(() => {
return () => {
client.cache.evict({ fieldName: "assets" });
client.cache.gc();
};
}, [client.cache]);

const t = useT();
const [deleteModalVisible, setDeleteModalVisible] = useState(false);
const [localSearchTerm, setLocalSearchTerm] = useState<string>(searchTerm ?? "");
Expand Down
2 changes: 2 additions & 0 deletions web/src/beta/features/Editor/Visualizer/convert-story.ts
Expand Up @@ -161,6 +161,8 @@ const processPropertyGroups = (
title: schema.translatedTitle || undefined,
description: schema.translatedDescription || undefined,
choices: schema.choices || undefined,
min: schema.min || undefined,
max: schema.max || undefined,
};

if (!used) {
Expand Down
2 changes: 2 additions & 0 deletions web/src/beta/lib/core/StoryPanel/hooks/useFieldComponent.tsx
Expand Up @@ -106,6 +106,8 @@ export const FieldComponent = ({
name={field?.title}
value={field?.value}
description={field?.description}
min={field?.min}
max={field?.max}
onChange={handlePropertyValueUpdate(groupId, propertyId, fieldId, field?.type)}
/>
)
Expand Down
1 change: 1 addition & 0 deletions web/src/beta/lib/core/StoryPanel/index.tsx
Expand Up @@ -166,6 +166,7 @@ export default StoryPanel;

const PanelWrapper = styled.div<{ bgColor?: string }>`
flex: 0 0 ${STORY_PANEL_WIDTH}px;
width: ${STORY_PANEL_WIDTH}px;
background: ${({ bgColor }) => bgColor};
color: ${({ theme }) => theme.content.weak};
`;
12 changes: 9 additions & 3 deletions web/src/services/api/projectApi.ts
Expand Up @@ -175,7 +175,9 @@ export default () => {
[updateProjectMutation, t, setNotification],
);

const [archiveProjectMutation] = useMutation(ARCHIVE_PROJECT);
const [archiveProjectMutation] = useMutation(ARCHIVE_PROJECT, {
refetchQueries: ["GetProject"],
});
const useArchiveProject = useCallback(
async (input: ArchiveProjectMutationVariables) => {
if (!input.projectId) return { status: "error" };
Expand Down Expand Up @@ -204,7 +206,9 @@ export default () => {
[archiveProjectMutation, t, setNotification],
);

const [deleteProjectMutation] = useMutation(DELETE_PROJECT);
const [deleteProjectMutation] = useMutation(DELETE_PROJECT, {
refetchQueries: ["GetProject"],
});
const useDeleteProject = useCallback(
async (input: DeleteProjectInput) => {
if (!input.projectId) return { status: "error" };
Expand All @@ -223,7 +227,9 @@ export default () => {
[deleteProjectMutation, t, setNotification],
);

const [updateProjectBasicAuthMutation] = useMutation(UPDATE_PROJECT_BASIC_AUTH);
const [updateProjectBasicAuthMutation] = useMutation(UPDATE_PROJECT_BASIC_AUTH, {
refetchQueries: ["GetProject"],
});
const useUpdateProjectBasicAuth = useCallback(
async (input: UpdateProjectBasicAuthMutationVariables) => {
if (!input.projectId) return { status: "error" };
Expand Down

0 comments on commit 0b60ec5

Please sign in to comment.