Skip to content

Commit

Permalink
fix using useContext hook
Browse files Browse the repository at this point in the history
  • Loading branch information
stCarolas committed Apr 1, 2024
1 parent 8b9da16 commit d6edfe5
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/components/ConfigurationPage/settings/BaseSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function BaseSettings({
.get(id)
?.properties?.filter(filter)
.map(
(prop) => (prop.type !== "custom" || customHandler) && prop.markup(),
(prop) => (prop.type !== "custom" || customHandler) && prop.markup(updateConfig),
)}
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function DonatersTopListSettings({ id }: { id: string }) {
?.properties?.filter((prop) => prop.tab === tab)
.map((prop) => {
if (prop.name === "type" || prop.name === "period") {
return prop.markup();
return prop.markup(updateConfig);
}
if (prop.name === "layout") {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ReactNode, useContext } from "react";
import { ReactNode } from "react";
import BooleanPropertyInput from "../settings/properties/BooleanPropertyInput";
import { WidgetsContext } from "../WidgetsContext";
import { DefaultWidgetProperty } from "./WidgetProperty";

export class BooleanProperty extends DefaultWidgetProperty {
Expand All @@ -26,8 +25,7 @@ export class BooleanProperty extends DefaultWidgetProperty {
);
}

markup(): ReactNode {
const { updateConfig } = useContext(WidgetsContext);
markup(updateConfig: Function): ReactNode {
return (
<>
<div key={this.name} className="widget-settings-item">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ReactNode, useContext } from "react";
import { ReactNode } from "react";
import ColorPicker from "../settings/ColorPicker";
import { WidgetsContext } from "../WidgetsContext";

export class ColorProperty {
widgetId: string | null;
Expand All @@ -26,8 +25,7 @@ export class ColorProperty {
this.tab = tab;
}

markup(): ReactNode {
const { updateConfig } = useContext(WidgetsContext);
markup(updateConfig: Function): ReactNode {
return (
<div key={this.name} className="widget-settings-item">
<label
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ReactNode, useContext } from "react";
import { ReactNode } from "react";
import { log } from "../../../logging";
import FontSelect from "../settings/FontSelect";
import { WidgetsContext } from "../WidgetsContext";

export class FontProperty {
widgetId: string | null;
Expand Down Expand Up @@ -39,8 +38,7 @@ export class FontProperty {
);
}

markup(): ReactNode {
const { updateConfig } = useContext(WidgetsContext);
markup(updateConfig: Function): ReactNode {
return (
<div key={this.name} className="widget-settings-item">
<label
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ReactNode, useContext } from "react";
import { ReactNode } from "react";
import { log } from "../../../logging";
import { WidgetsContext } from "../WidgetsContext";
import { DefaultWidgetProperty } from "./WidgetProperty";

export class NumberProperty extends DefaultWidgetProperty {
Expand All @@ -27,8 +26,7 @@ export class NumberProperty extends DefaultWidgetProperty {
);
}

markup(): ReactNode {
const { updateConfig } = useContext(WidgetsContext);
markup(updateConfig: Function): ReactNode {
return (
<div key={this.name} className="widget-settings-item">
<label
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ReactNode, useContext } from "react";
import { WidgetsContext } from "../WidgetsContext";
import { ReactNode } from "react";
import { DefaultWidgetProperty } from "./WidgetProperty";

export class SingleChoiceProperty extends DefaultWidgetProperty {
Expand All @@ -18,16 +17,10 @@ export class SingleChoiceProperty extends DefaultWidgetProperty {
this.options = options ?? [];
}

markup(): ReactNode {
const { updateConfig } = useContext(WidgetsContext);
markup(updateConfig: Function): ReactNode {
return (
<div key={this.name} className="widget-settings-item">
<label
htmlFor={`${this.widgetId}_${this.name}`}
className="widget-settings-name"
>
{this.displayName}
</label>
<label className="widget-settings-name">{this.displayName}</label>
<select
value={this.value}
className="widget-settings-value select"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ReactNode, useContext } from "react";
import { WidgetsContext } from "../WidgetsContext";
import { ReactNode } from "react";
import { DefaultWidgetProperty } from "./WidgetProperty";

export class StringValueProperty extends DefaultWidgetProperty {
Expand All @@ -25,8 +24,7 @@ export class StringValueProperty extends DefaultWidgetProperty {
);
}

markup(): ReactNode {
const { updateConfig } = useContext(WidgetsContext);
markup(updateConfig: Function): ReactNode {
return (
<div key={this.name} className="widget-settings-item">
<label
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ReactNode, useContext } from "react";
import { WidgetsContext } from "../WidgetsContext";
import { ReactNode } from "react";
import { DefaultWidgetProperty } from "./WidgetProperty";

export class TextProperty extends DefaultWidgetProperty {
Expand All @@ -25,8 +24,7 @@ export class TextProperty extends DefaultWidgetProperty {
);
}

markup(): ReactNode {
const { updateConfig } = useContext(WidgetsContext);
markup(updateConfig: Function): ReactNode {
return (
<div key={this.name} className="widget-settings-item">
<label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface WidgetProperty {
value: any;
displayName: string;
tab?: string;
markup: () => ReactNode;
markup: (updateConfig: Function) => ReactNode;
copy: () => WidgetProperty;
}

Expand Down Expand Up @@ -36,7 +36,7 @@ export class DefaultWidgetProperty {
this._tab = tab;
}

markup(): ReactNode {
markup(updateConfig: Function): ReactNode {
return React.createElement("div");
}

Expand Down

0 comments on commit d6edfe5

Please sign in to comment.