Skip to content

Commit

Permalink
Added SDK and type changes for multi-range notif
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNilesh committed Nov 29, 2023
1 parent e1a3c34 commit 600edd9
Show file tree
Hide file tree
Showing 12 changed files with 206 additions and 77 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@mui/lab": "^5.0.0-alpha.72",
"@mui/material": "^5.5.0",
"@pushprotocol/ledgerlive": "latest",
"@pushprotocol/restapi": "1.4.38",
"@pushprotocol/restapi": "1.4.41",
"@pushprotocol/socket": "0.5.3",
"@pushprotocol/uiweb": "1.1.19",
"@reduxjs/toolkit": "^1.7.1",
Expand Down
7 changes: 6 additions & 1 deletion src/components/SendNotifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,12 @@ function SendNotifications() {
if (channelSettings) {
const settingsOptions = channelSettings.map((setting) => ({
label:
setting.type === 2 ? (
setting.type === 3 ? (
<DropdownLabel>
<div>{setting.description}</div>
<Tag>Multi-Range</Tag>
</DropdownLabel>
) : setting.type === 2 ? (
<DropdownLabel>
<div>{setting.description}</div>
<Tag>Range</Tag>
Expand Down
33 changes: 28 additions & 5 deletions src/components/channel/AddSettingModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ const AddSettingModalContent = ({

// for range slider
const [defaultStartValue, setDefaultStartValue] = useState<string>(
settingToEdit && settingToEdit.type === 3 ? settingToEdit.defaultStartVal.toString() : ''
settingToEdit && settingToEdit.type === 3 ? settingToEdit.default.lower.toString() : ''
);
const [defaultEndValue, setDefaultEndValue] = useState<string>(
settingToEdit && settingToEdit.type === 3 ? settingToEdit.defaultEndVal.toString() : ''
settingToEdit && settingToEdit.type === 3 ? settingToEdit.default.upper.toString() : ''
);
const [sliderPreviewStartVal, setSliderPreviewStartVal] = useState<number>();
const [sliderPreviewEndVal, setSliderPreviewEndVal] = useState<number>();
Expand All @@ -117,17 +117,33 @@ const AddSettingModalContent = ({
if (
isAllFilledAndValid({
setErrorInfo,
defaultValue,
defaultValue: enableMultiRange ? { lower: defaultStartValue, upper: defaultEndValue } : defaultValue,
settingName,
lowerLimit,
type: isRange ? 2 : 1,
type: isRange ? (enableMultiRange ? 3 : 2) : 1,
upperLimit,
sliderStep,
})
) {
const index = settingToEdit ? settingToEdit.index : Math.floor(Math.random() * 1000000);
const settingData: ChannelSetting = isRange
? {
? enableMultiRange
?
{
type: 3,
default: {
lower: Number(defaultStartValue),
upper: Number(defaultEndValue)
},
enabled: isDefault,
description: settingName,
index: index,
lowerLimit: Number(lowerLimit),
upperLimit: Number(upperLimit),
ticker: Number(sliderStep),
}
:
{
type: 2,
default: Number(defaultValue),
enabled: isDefault,
Expand Down Expand Up @@ -379,10 +395,13 @@ const AddSettingModalContent = ({
color={theme.editChannelPrimaryText}
value={defaultStartValue}
onChange={(e) => {
setErrorInfo((prev) => ({ ...prev, defaultStart: undefined }));
if (isInvalidNumber(e.target.value)) return;
setDefaultStartValue(e.target.value);
setSliderPreviewStartVal(Number(e.target.value));
}}
autocomplete="off"
hasError={errorInfo?.defaultStart ? true : false}
/>
<Label padding="0px 16px">to</Label>
<MaxWidthInput
Expand All @@ -402,12 +421,16 @@ const AddSettingModalContent = ({
color={theme.editChannelPrimaryText}
value={defaultEndValue}
onChange={(e) => {
setErrorInfo((prev) => ({ ...prev, defaultEnd: undefined }));
if (isInvalidNumber(e.target.value)) return;
setDefaultEndValue(e.target.value);
setSliderPreviewEndVal(Number(e.target.value));
}}
autocomplete="off"
hasError={errorInfo?.defaultEnd ? true : false}
/>
</Item>
<ErrorInfo>{errorInfo?.defaultStart || errorInfo?.defaultEnd}</ErrorInfo>
</Item>
}
<Item
Expand Down
1 change: 1 addition & 0 deletions src/components/channel/ChannelInfoList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const ChannelInfoList = (props: ChannelInfoListProps) => {
<>
<NotificationSettingName>{item.description}</NotificationSettingName>
{item.type === 2 && <Tag>Range</Tag>}
{item.type === 3 && <Tag>Multi-Range</Tag>}
</>
)}
{props.isAddress && isOwner(props.account, item) && <Tag>Creator</Tag>}
Expand Down
28 changes: 27 additions & 1 deletion src/components/channel/NotificationSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,32 @@ function NotificationSettings() {
default: setting.default ? 1 : 0,
};
}
if (setting.type === 2) {
else if (setting.type === 2) {
console.log(
{
type: setting.type,
description: setting.description,
default: setting.default,
data: {
lower: setting.lowerLimit,
upper: setting.upperLimit,
ticker: setting.ticker,
enabled: setting.enabled,
},
}
)
return {
type: setting.type,
description: setting.description,
default: setting.default,
data: {
lower: setting.lowerLimit,
upper: setting.upperLimit,
ticker: setting.ticker,
enabled: setting.enabled,
},
};
} else if (setting.type === 3) {
console.log(
{
type: setting.type,
Expand All @@ -169,6 +194,7 @@ function NotificationSettings() {
};
}
});
console.log(settingData);
await userPushSDKInstance.channel.setting(settingData);

dispatch(updateChannelSetting({ channelAddress, settings }));
Expand Down
53 changes: 27 additions & 26 deletions src/components/dropdowns/OptinNotifSettingDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const OptinNotifSettingDropdownContainer: React.FC<OptinNotifSettingDropdownCont

const theme = useTheme();

const handleSliderChange = (index: number, value: number) => {
const handleSliderChange = (index: number, value: number | { lower: number, upper: number }) => {
const updatedSettings = [...modifiedSettings];
updatedSettings[index].default = value;
setModifiedSettings(updatedSettings);
Expand Down Expand Up @@ -84,36 +84,36 @@ const OptinNotifSettingDropdownContainer: React.FC<OptinNotifSettingDropdownCont
handleDiameter={12}
/>
</DropdownSwitchItem>
{setting.type === 2 && setting.enabled === true && (
<DropdownSliderItem>
{setting.type === 2 && setting.enabled === true && (
<DropdownSliderItem>
<SpanV2 color={theme.fontColor} fontSize="18px" fontWeight='600' alignSelf="flex-start">
{setting.default}
</SpanV2>
<InputSlider
val={setting.default}
max={setting.upperLimit}
min={setting.lowerLimit}
step={setting.ticker || 1}
val={setting.default}
defaultVal={setting.default}
onChange={({ x }) => handleSliderChange(index, x)}
/>
<SpanV2 color={theme.fontColor} fontSize="16px" fontWeight='500' textAlign="right" margin="0 0 0 16px">
{setting.default}
</SpanV2>
</DropdownSliderItem>
)}
</DropdownSliderItem>
)}
{setting.type === 3 && setting.enabled === true && (
<DropdownSliderItem>
<RangeSlider
max={setting.upperLimit}
min={setting.lowerLimit}
step={setting.ticker || 1}
startVal={setting.defaultStartVal}
endVal={setting.defaultEndVal}
defaultStartVal={setting.defaultStartVal}
defaultEndVal={setting.defaultEndVal}
onChange={({ x }) => handleSliderChange(index, x)}
/>
<SpanV2 color={theme.fontColor} fontSize="16px" fontWeight='500' textAlign="right" margin="0 0 0 16px">
{setting.defaultStartVal} - {setting.defaultEndVal}
</SpanV2>
<SpanV2 color={theme.fontColor} fontSize="18px" fontWeight='600' alignSelf="flex-start">
{setting.default.lower} - {setting.default.upper}
</SpanV2>
<RangeSlider
startVal={setting.default.lower}
endVal={setting.default.upper}
max={setting.upperLimit}
min={setting.lowerLimit}
step={setting.ticker || 1}
defaultStartVal={setting.default.lower}
defaultEndVal={setting.default.upper}
onChange={({ startVal, endVal }) => handleSliderChange(index, {lower: startVal, upper: endVal})}
/>
</DropdownSliderItem>
)}
</DropdownInnerContainer>
Expand Down Expand Up @@ -276,14 +276,14 @@ const DropdownSwitchItem = styled.div`
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 0px;
padding: 12px 0px;
`;

const DropdownSubmitItem = styled.div`
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 0px;
padding: 12px 0px;
`;

const DropdownSubmitButton = styled.button`
Expand Down Expand Up @@ -329,9 +329,10 @@ const DropdownSubmitButton = styled.button`

const DropdownSliderItem = styled.div`
display: flex;
justify-content: space-between;
flex-direction: column;
gap: 13px;
align-items: center;
padding-bottom: 10px;
padding-bottom: 12px;
`;

const ActionTitle = styled.span<{ hideIt: boolean }>`
Expand Down
58 changes: 41 additions & 17 deletions src/components/dropdowns/UpdateNotifSettingDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useDispatch, useSelector } from "react-redux";
// Internal Components
import { DropdownBtnHandler } from "./DropdownBtnHandler";
import InputSlider from "components/reusables/sliders/InputSlider";
import RangeSlider from "components/reusables/sliders/RangeSlider";

// Internal Configs
import { SpanV2 } from "components/reusables/SharedStylingV2";
Expand Down Expand Up @@ -43,7 +44,7 @@ const UpdateNotifSettingDropdownContainer: React.FC<UpdateNotifSettingDropdownCo

const theme = useTheme();

const handleSliderChange = (index: number, value: number) => {
const handleSliderChange = (index: number, value: number | {lower: number, upper: number}) => {
const updatedSettings = [...modifiedSettings];
updatedSettings[index].user = value;
setModifiedSettings(updatedSettings);
Expand All @@ -56,11 +57,16 @@ const UpdateNotifSettingDropdownContainer: React.FC<UpdateNotifSettingDropdownCo
// Use a type guard to narrow the type to UserSetting of type 1
const setting = updatedSettings[index] as UserSetting & { type: 1 };
setting.user = !setting.user;
} else {
} else if (updatedSettings[index].type === 2) {
// Type 2
// Use a type guard to narrow the type to UserSetting of type 2
const setting = updatedSettings[index] as UserSetting & { type: 2 };
setting.enabled = !setting.enabled;
} else {
// Type 3
// Use a type guard to narrow the type to UserSetting of type 2
const setting = updatedSettings[index] as UserSetting & { type: 3 };
setting.enabled = !setting.enabled;
}
setModifiedSettings(updatedSettings);
};
Expand All @@ -87,17 +93,34 @@ const UpdateNotifSettingDropdownContainer: React.FC<UpdateNotifSettingDropdownCo
</DropdownSwitchItem>
{setting.type === 2 && setting.enabled === true && (
<DropdownSliderItem>
<InputSlider
val={setting.user}
max={setting.upperLimit}
min={setting.lowerLimit}
step={setting.ticker || 1}
defaultVal={setting.default}
onChange={({ x }) => handleSliderChange(index, x)}
/>
<SpanV2 color={theme.fontColor} fontSize="16px" fontWeight='500' textAlign="right" margin="0 0 0 16px">
{setting.user}
</SpanV2>
<SpanV2 color={theme.fontColor} fontSize="18px" fontWeight='600' alignSelf="flex-start">
{setting.user || setting.default}
</SpanV2>
<InputSlider
val={setting.user}
max={setting.upperLimit}
min={setting.lowerLimit}
step={setting.ticker || 1}
defaultVal={setting.default}
onChange={({ x }) => handleSliderChange(index, x)}
/>
</DropdownSliderItem>
)}
{setting.type === 3 && setting.enabled === true && (
<DropdownSliderItem>
<SpanV2 color={theme.fontColor} fontSize="18px" fontWeight='600' alignSelf="flex-start">
{setting.user.lower || setting.default.lower} - {setting.user.upper || setting.default.upper}
</SpanV2>
<RangeSlider
startVal={setting.user.lower || setting.default.lower}
endVal={setting.user.upper || setting.default.upper}
max={setting.upperLimit}
min={setting.lowerLimit}
step={setting.ticker || 1}
defaultStartVal={setting.default.lower}
defaultEndVal={setting.default.upper}
onChange={({ startVal, endVal }) => handleSliderChange(index, {lower: startVal, upper: endVal})}
/>
</DropdownSliderItem>
)}
</DropdownInnerContainer>
Expand Down Expand Up @@ -258,14 +281,14 @@ const DropdownSwitchItem = styled.div`
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 0px;
padding: 12px 0px;
`;

const DropdownSubmitItem = styled.div`
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 0px;
padding: 12px 0px;
`;

const DropdownSubmitButton = styled.button`
Expand Down Expand Up @@ -311,9 +334,10 @@ const DropdownSubmitButton = styled.button`

const DropdownSliderItem = styled.div`
display: flex;
justify-content: space-between;
flex-direction: column;
gap: 13px;
align-items: center;
padding-bottom: 10px;
padding-bottom: 12px;
`;

const ActionTitle = styled.span<{ hideIt: boolean }>`
Expand Down
2 changes: 1 addition & 1 deletion src/components/reusables/sliders/RangeSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const RangeSlider = ({
thumbStartRef.current.style.left = `${((startVal - min) / (max - min)) * 98}%`;
inactiveLeftRef.current.style.width = `${((startVal - min) / (max - min)) * 100}%`;
activeRef.current.style.width = `${((endVal - startVal) / (max - min)) * 100}%`;
thumbEndRef.current.style.left = `${((endVal) / (max - min)) * 98}%`;
thumbEndRef.current.style.left = `${((endVal - min) / (max - min)) * 95}%`;
inactiveRightRef.current.style.width = `${((max - endVal) / (max - min)) * 100}%`;

previewSliderStartRef.current?.style.setProperty(
Expand Down
Loading

0 comments on commit 600edd9

Please sign in to comment.