Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
38 changes: 21 additions & 17 deletions src/components/mod-loader-cards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface ModLoaderCardsProps extends BoxProps {
displayMode: "entry" | "selector";
loading?: boolean;
onTypeSelect?: (type: ModLoaderType) => void;
expandedType?: ModLoaderType | null;
}

const ModLoaderCards: React.FC<ModLoaderCardsProps> = ({
Expand All @@ -31,6 +32,7 @@ const ModLoaderCards: React.FC<ModLoaderCardsProps> = ({
displayMode,
loading = false,
onTypeSelect,
expandedType,
...boxProps
}) => {
const { t } = useTranslation();
Expand Down Expand Up @@ -93,23 +95,25 @@ const ModLoaderCards: React.FC<ModLoaderCardsProps> = ({
</Text>
</VStack>
</HStack>
<IconButton
aria-label={type}
icon={
<Icon
as={
displayMode === "selector" && isSelected
? LuX
: LuChevronRight
}
boxSize={3.5}
/>
}
variant="ghost"
size="xs"
disabled={loading}
onClick={() => onTypeSelect?.(type)}
/>
{displayMode === "selector" && expandedType && !isSelected ? null : (
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为啥条件渲染

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不是控制是否显示箭头/x吗

<IconButton
aria-label={type}
icon={
<Icon
as={
displayMode === "selector" && isSelected
? LuX
: LuChevronRight
}
boxSize={3.5}
/>
}
variant="ghost"
size="xs"
disabled={loading}
onClick={() => onTypeSelect?.(type)}
/>
)}
</Flex>
</Card>
);
Expand Down
28 changes: 19 additions & 9 deletions src/components/mod-loader-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { Section } from "@/components/common/section";
import ModLoaderCards from "@/components/mod-loader-cards";
import { useLauncherConfig } from "@/contexts/config";
import { ModLoaderType } from "@/enums/instance";
import {
GameResourceInfo,
ModLoaderResourceInfo,
Expand All @@ -37,12 +38,16 @@ interface ModLoaderSelectorProps {
selectedGameVersion: GameResourceInfo;
selectedModLoader: ModLoaderResourceInfo;
onSelectModLoader: (v: ModLoaderResourceInfo) => void;
expandedLoaderType?: ModLoaderType | null;
onExpandLoaderType?: (loaderType: ModLoaderType | null) => void;
}

export const ModLoaderSelector: React.FC<ModLoaderSelectorProps> = ({
selectedGameVersion,
selectedModLoader,
onSelectModLoader,
expandedLoaderType,
onExpandLoaderType,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这两个参数我之前脑测感觉没必要加啊

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果不是外部传入的情况下会出现进入step2时会记录之前选择的selectedModLoader,却没有记录之前的expandedLoaderType,导致虽然内容有展开但是所有的modloadercard都有箭头

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没事了脑子没转过来想到怎么写了

...props
}) => {
const { t } = useTranslation();
Expand Down Expand Up @@ -123,16 +128,21 @@ export const ModLoaderSelector: React.FC<ModLoaderSelectorProps> = ({
currentVersion={selectedModLoader.version}
displayMode="selector"
loading={loading}
expandedType={expandedLoaderType}
onTypeSelect={(loaderType) => {
if (loaderType !== selectedModLoader.loaderType) {
onSelectModLoader({
loaderType,
version: "",
description: "",
stable: false,
});
} else {
onSelectModLoader(defaultModLoaderResourceInfo);
if (onExpandLoaderType) {
if (expandedLoaderType === loaderType) {
onExpandLoaderType(null);
onSelectModLoader(defaultModLoaderResourceInfo);
} else {
onExpandLoaderType(loaderType);
onSelectModLoader({
loaderType,
version: "",
description: "",
stable: false,
});
}
}
}}
w="100%"
Expand Down
14 changes: 13 additions & 1 deletion src/components/modals/create-instance-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { InstanceBasicSettings } from "@/components/instance-basic-settings";
import { ModLoaderSelector } from "@/components/mod-loader-selector";
import { useLauncherConfig } from "@/contexts/config";
import { useToast } from "@/contexts/toast";
import { ModLoaderType } from "@/enums/instance";
import { GameDirectory } from "@/models/config";
import {
GameResourceInfo,
Expand Down Expand Up @@ -75,6 +76,8 @@ export const CreateInstanceModal: React.FC<Omit<ModalProps, "children">> = ({
const [instanceIconSrc, setInstanceIconSrc] = useState("");
const [instanceDirectory, setInstanceDirectory] = useState<GameDirectory>();
const [isLoading, setIsLoading] = useState(false);
const [expandedLoaderType, setExpandedLoaderType] =
useState<ModLoaderType | null>(null);

useEffect(() => {
setSelectedModLoader(defaultModLoaderResourceInfo);
Expand Down Expand Up @@ -158,13 +161,21 @@ export const CreateInstanceModal: React.FC<Omit<ModalProps, "children">> = ({
selectedGameVersion={selectedGameVersion}
selectedModLoader={selectedModLoader}
onSelectModLoader={setSelectedModLoader}
expandedLoaderType={expandedLoaderType}
onExpandLoaderType={setExpandedLoaderType}
/>
</ModalBody>
<ModalFooter>
<Button variant="ghost" onClick={modalProps.onClose}>
{t("General.cancel")}
</Button>
<Button variant="ghost" onClick={() => setActiveStep(0)}>
<Button
variant="ghost"
onClick={() => {
setExpandedLoaderType(null);
setActiveStep(0);
}}
>
{t("General.previous")}
</Button>
<Button
Expand Down Expand Up @@ -198,6 +209,7 @@ export const CreateInstanceModal: React.FC<Omit<ModalProps, "children">> = ({
primaryColor,
selectedGameVersion,
selectedModLoader,
expandedLoaderType,
setActiveStep,
t,
]);
Expand Down
Loading