feat: Refactor matrix state management and integrate zustand for better state handling

This commit is contained in:
2025-12-27 00:12:16 +01:00
parent 2a3dc9f0e0
commit 8f3c652299
5 changed files with 153 additions and 85 deletions
+10 -9
View File
@@ -5,18 +5,19 @@ import ColorSelector from "@/src/components/themed/ColorSelector";
import {View} from "react-native";
import ThemedSegmentedButtons from "@/src/components/themed/ThemedSegmentedButtons";
import { MatrixState } from '@/src/model/User';
import {useMatrix} from "@/app/(tabs)/_layout";
import { useMatrixStore } from "@/src/stores";
type TextProps = MatrixState['text'];
export default function TextScreen() {
const { matrixState, updateMatrixState } = useMatrix();
const textConfig = useMatrixStore((s) => s.matrixState.text);
const updateTextConfig = useMatrixStore((s) => s.updateTextConfig);
const setGlobalMode = useMatrixStore((s) => s.setGlobalMode);
const matrixState = useMatrixStore((s) => s.matrixState);
const updateTextProp = (prop: Partial<TextProps>) => {
updateMatrixState({
text: { ...matrixState.text, ...prop },
global: { ...matrixState.global, mode: 'text' }
});
updateTextConfig(prop);
setGlobalMode('text');
};
const handleSendToMatrix = () => {
@@ -29,17 +30,17 @@ export default function TextScreen() {
<View className="gap-4">
<ThemedTextInput
label="Text"
value={matrixState.text.text}
value={textConfig.text}
onChangeText={(text) => updateTextProp({ text })}
/>
<ColorSelector
onSelect={(color) => updateTextProp({ color })}
defaultColor={matrixState.text.color}
defaultColor={textConfig.color}
/>
<ThemedSegmentedButtons
value={matrixState.text.align}
value={textConfig.align}
onValueChange={(align) => updateTextProp({ align })}
options={{
left: 'Links',