Skip to content

Commit

Permalink
Fixed Custom Icon Persistance Across New View Creations (twentyhq#9070)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehconitin authored Dec 17, 2024
1 parent 1f4d135 commit ac2894c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { viewPickerIsPersistingComponentState } from '@/views/view-picker/states
import { viewPickerKanbanFieldMetadataIdComponentState } from '@/views/view-picker/states/viewPickerKanbanFieldMetadataIdComponentState';
import { viewPickerSelectedIconComponentState } from '@/views/view-picker/states/viewPickerSelectedIconComponentState';
import { viewPickerTypeComponentState } from '@/views/view-picker/states/viewPickerTypeComponentState';
import { useState } from 'react';
import { useMemo, useState } from 'react';

const StyledNoKanbanFieldAvailableContainer = styled.div`
color: ${({ theme }) => theme.font.color.light};
Expand All @@ -41,7 +41,7 @@ const StyledNoKanbanFieldAvailableContainer = styled.div`
`;

export const ViewPickerContentCreateMode = () => {
const { setViewPickerMode } = useViewPickerMode();
const { viewPickerMode, setViewPickerMode } = useViewPickerMode();
const [hasManuallySelectedIcon, setHasManuallySelectedIcon] = useState(false);

const [viewPickerInputName, setViewPickerInputName] =
Expand Down Expand Up @@ -92,9 +92,20 @@ export const ViewPickerContentCreateMode = () => {
const defaultIcon =
viewPickerType === ViewType.Kanban ? 'IconLayoutKanban' : 'IconTable';

const selectedIcon = hasManuallySelectedIcon
? viewPickerSelectedIcon
: defaultIcon;
const selectedIcon = useMemo(() => {
if (hasManuallySelectedIcon) {
return viewPickerSelectedIcon;
}
if (viewPickerMode === 'create-from-current') {
return viewPickerSelectedIcon || defaultIcon;
}
return defaultIcon;
}, [
hasManuallySelectedIcon,
viewPickerSelectedIcon,
viewPickerMode,
defaultIcon,
]);

const onIconChange = ({ iconKey }: { iconKey: string }) => {
setViewPickerIsDirty(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { useRecoilComponentStateV2 } from '@/ui/utilities/state/component-state/
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
import { useSetRecoilComponentStateV2 } from '@/ui/utilities/state/component-state/hooks/useSetRecoilComponentStateV2';
import { useGetCurrentView } from '@/views/hooks/useGetCurrentView';
import { ViewType } from '@/views/types/ViewType';
import { useGetAvailableFieldsForKanban } from '@/views/view-picker/hooks/useGetAvailableFieldsForKanban';
import { useViewPickerMode } from '@/views/view-picker/hooks/useViewPickerMode';
import { viewPickerInputNameComponentState } from '@/views/view-picker/states/viewPickerInputNameComponentState';
import { viewPickerIsDirtyComponentState } from '@/views/view-picker/states/viewPickerIsDirtyComponentState';
import { viewPickerIsPersistingComponentState } from '@/views/view-picker/states/viewPickerIsPersistingComponentState';
Expand All @@ -21,11 +23,12 @@ export const ViewPickerContentEffect = () => {
const setViewPickerInputName = useSetRecoilComponentStateV2(
viewPickerInputNameComponentState,
);
const { viewPickerMode } = useViewPickerMode();

const [viewPickerKanbanFieldMetadataId, setViewPickerKanbanFieldMetadataId] =
useRecoilComponentStateV2(viewPickerKanbanFieldMetadataIdComponentState);

const setViewPickerType = useSetRecoilComponentStateV2(
const [viewPickerType, setViewPickerType] = useRecoilComponentStateV2(
viewPickerTypeComponentState,
);

Expand Down Expand Up @@ -54,7 +57,13 @@ export const ViewPickerContentEffect = () => {
!viewPickerIsPersisting &&
!viewPickerIsDirty
) {
setViewPickerSelectedIcon(referenceView.icon);
const defaultIcon =
viewPickerType === ViewType.Kanban ? 'IconLayoutKanban' : 'IconTable';
if (viewPickerMode === 'create-empty') {
setViewPickerSelectedIcon(defaultIcon);
} else {
setViewPickerSelectedIcon(referenceView.icon);
}
setViewPickerInputName(referenceView.name);
setViewPickerType(referenceView.type);
}
Expand All @@ -65,6 +74,8 @@ export const ViewPickerContentEffect = () => {
setViewPickerType,
viewPickerIsPersisting,
viewPickerIsDirty,
viewPickerMode,
viewPickerType,
]);

useEffect(() => {
Expand Down

0 comments on commit ac2894c

Please sign in to comment.