Skip to content

Commit

Permalink
updated emoji options, fixed claim role, added roles to gathering and…
Browse files Browse the repository at this point in the history
… poll requests, added option text component to create poll page, bumped sdk
  • Loading branch information
AntGe committed Dec 3, 2024
1 parent de02ef4 commit c3c8154
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 129 deletions.
9 changes: 4 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@aut-labs/abi-types": "^0.0.87-dev",
"@aut-labs/connector": "^0.0.205",
"@aut-labs/d-aut": "^1.0.205-dev",
"@aut-labs/sdk": "^0.0.227-dev",
"@aut-labs/sdk": "^0.0.229-dev",
"@emoji-mart/data": "^1.2.1",
"@emoji-mart/react": "^1.1.1",
"@emotion/react": "^11.11.3",
Expand Down
5 changes: 4 additions & 1 deletion src/api/contribution-types/discord-gathering.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ export class DiscordGatheringContributionProperties extends TaskContributionProp
channelId: string;
duration: number;
guildId: string;
roles: string[];

constructor(data: DiscordGatheringContributionProperties) {
super(data);
this.channelId = data.channelId;
this.duration = data.duration;
this.guildId = data.guildId;
this.roles = data.roles;
}
}

Expand All @@ -30,7 +32,8 @@ export class DiscordGatheringContribution<
properties: {
duration: taskContribution.properties.duration,
channelId: taskContribution.properties.channelId,
guildId: taskContribution.properties.guildId
guildId: taskContribution.properties.guildId,
roles: taskContribution.properties.roles
}
} as BaseNFTModel<any>;
}
Expand Down
7 changes: 5 additions & 2 deletions src/api/contribution-types/discord-poll-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ export class DiscordPollContributionProperties extends TaskContributionPropertie
channelId: string;
duration: string;
guildId: string;
options: string[];
options: { option: string; emoji: string }[];
roles: string[];

constructor(data: DiscordPollContributionProperties) {
super(data);
this.channelId = data.channelId;
this.duration = data.duration;
this.guildId = data.guildId;
this.options = data.options || [];
this.roles = data.roles;
}
}

Expand All @@ -33,7 +35,8 @@ export class DiscordPollContribution<
duration: taskContribution.properties.duration,
channelId: taskContribution.properties.channelId,
guildId: taskContribution.properties.guildId,
options: taskContribution.properties.options
options: taskContribution.properties.options,
roles: taskContribution.properties.roles
}
} as BaseNFTModel<any>;
}
Expand Down
123 changes: 63 additions & 60 deletions src/api/contributions.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { PullRequestContribution } from "./contribution-types/github-pr.model";
import { JoinDiscordContribution } from "./contribution-types/discord-join.model";
import { DiscordPollContribution } from "./contribution-types/discord-poll-model";
import { create } from "@mui/material/styles/createTransitions";
import { environment } from "./environment";

const hubServiceCache: Record<string, Hub> = {};

Expand Down Expand Up @@ -79,7 +80,6 @@ const createContribution = async (
},
overrides
);

if (!response.isSuccess) {
return {
error: response.errorMessage
Expand Down Expand Up @@ -113,7 +113,6 @@ const createTwitterRetweetContribution = async (
}: { contribution: RetweetContribution; autSig: AuthSig },
api: BaseQueryApi
) => {
debugger;
const nft = RetweetContribution.getContributionNFT(contribution);
return createContribution(contribution, nft, api);
};
Expand All @@ -126,42 +125,42 @@ const createDiscordGatheringContribution = async (
api: BaseQueryApi
) => {
const nft = DiscordGatheringContribution.getContributionNFT(contribution);
// const result = await createContribution(contribution, nft, api);

try {
const gatheringPayload = {
guildId: contribution.properties.guildId,
channelId: contribution.properties.channelId,
title: contribution.name,
description: contribution.description,
startDate: new Date(contribution.properties.startDate * 1000), // Convert unix to Date
endDate: new Date(contribution.properties.endDate * 1000),
roles: [contribution.properties.role],
allCanAttend: false,
weight: contribution.properties.points,
taskId: contribution.properties.taskId
};
const response = await fetch(
"http://localhost:4005/api/discord/gathering",
{
const result = await createContribution(contribution, nft, api);
if (!result.error) {
try {
const gatheringPayload = {
guildId: contribution.properties.guildId,
channelId: contribution.properties.channelId,
title: contribution.name,
description: contribution.description,
contributionId: result.data,
startDate: new Date(contribution.properties.startDate * 1000), // Convert unix to Date
endDate: new Date(contribution.properties.endDate * 1000),
roles: contribution.properties.roles,
allCanAttend: false,
weight: contribution.properties.points,
taskId: contribution.properties.taskId
};
const response = await fetch(`${environment.apiUrl}/discord/gathering`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(gatheringPayload)
});

if (!response.ok) {
throw new Error("Failed to create Discord gathering");
}
);

if (!response.ok) {
throw new Error("Failed to create Discord gathering");
const gathering = await response.json();
return { gathering } as any;
} catch (error) {
console.error("Discord gathering creation failed:", error);
return { gatheringError: error.message } as any;
}

const gathering = await response.json();
return { gathering } as any;
} catch (error) {
console.error("Discord gathering creation failed:", error);
return { gatheringError: error.message } as any;
}
return { pollError: result.error } as any;
};

const createDiscordPollContribution = async (
Expand All @@ -172,40 +171,44 @@ const createDiscordPollContribution = async (
api: BaseQueryApi
) => {
const nft = DiscordPollContribution.getContributionNFT(contribution);
// const result = await createContribution(contribution, nft, api);
debugger;
try {
const pollPayload = {
guildId: contribution.properties.guildId,
channelId: contribution.properties.channelId,
title: contribution.name,
options: contribution.properties.options,
description: contribution.description,
startDate: new Date(contribution.properties.startDate * 1000), // Convert unix to Date
endDate: new Date(contribution.properties.endDate * 1000),
roles: [contribution.properties.role],
allCanAttend: false,
weight: contribution.properties.points,
taskId: contribution.properties.taskId
};
const response = await fetch("http://localhost:4005/api/discord/poll", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(pollPayload)
});
const result = await createContribution(contribution, nft, api);

if (!response.ok) {
throw new Error("Failed to create Discord gathering");
}
if (!result.error) {
try {
const pollPayload = {
guildId: contribution.properties.guildId,
channelId: contribution.properties.channelId,
contributionId: result.data,
title: contribution.name,
options: contribution.properties.options,
description: contribution.description,
startDate: new Date(contribution.properties.startDate * 1000), // Convert unix to Date
endDate: new Date(contribution.properties.endDate * 1000),
allCanAttend: false,
roles: contribution.properties.roles,
weight: contribution.properties.points,
taskId: contribution.properties.taskId
};
const response = await fetch(`${environment.apiUrl}/discord/poll`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(pollPayload)
});

const poll = await response.json();
return { poll } as any;
} catch (error) {
console.error("Discord poll creation failed:", error);
return { pollError: error.message } as any;
if (!response.ok) {
throw new Error("Failed to create Discord gathering");
}

const poll = await response.json();
return { poll } as any;
} catch (error) {
console.error("Discord poll creation failed:", error);
return { pollError: error.message } as any;
}
}
return { pollError: result.error } as any;
};

const createJoinDiscordContribution = async (
Expand Down
65 changes: 28 additions & 37 deletions src/components/EmojiInputPicker/EmojiInputPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,23 @@ import {
IconButton,
Popover,
Paper,
Box,
InputAdornment,
TextFieldProps
} from "@mui/material";
import EmojiIcon from "@assets/smile-emoji.svg?react";

// Helper functions for emoji handling
const removeEmojis = (text = "") => {
return text.replace(/[^\p{L}\p{N}\p{P}\p{Z}^$\n]/gu, "").trim();
};

const hasEmoji = (text: string) => {
const regexExp =
/(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/gi;
return regexExp.test(text);
};

interface EmojiInputPickerProps extends Omit<TextFieldProps, "onChange"> {
onChange?: (value: string) => void;
interface EmojiOptionInputProps extends Omit<TextFieldProps, "onChange"> {
onChange?: (value: { option: string; emoji: string }) => void;
value?: { option: string; emoji: string };
emojiButtonProps?: {
disabled?: boolean;
};
}

const EmojiInputPicker: React.FC<EmojiInputPickerProps> = ({
const EmojiOptionInput: React.FC<EmojiOptionInputProps> = ({
onChange,
value = "",
value = { option: "", emoji: "" },
emojiButtonProps,
InputProps,
...textFieldProps
Expand All @@ -48,37 +39,36 @@ const EmojiInputPicker: React.FC<EmojiInputPickerProps> = ({
};

const handleEmojiSelect = (emoji: { native: string }) => {
if (inputRef.current) {
const cursorPosition = inputRef.current.selectionStart || 0;
const textBeforeCursor = String(value).slice(0, cursorPosition);
const textAfterCursor = String(value).slice(cursorPosition);

const newText = `${textBeforeCursor}${emoji.native}${textAfterCursor}`;
onChange?.(newText);

handleClose();
onChange?.({
option: value.option,
emoji: emoji.native
});
handleClose();
};

// Restore focus and cursor position
setTimeout(() => {
inputRef.current?.focus();
const newPosition = cursorPosition + emoji.native.length;
inputRef.current?.setSelectionRange(newPosition, newPosition);
}, 0);
}
const handleOptionChange = (e: React.ChangeEvent<HTMLInputElement>) => {
onChange?.({
option: e.target.value,
emoji: value.emoji
});
};

const open = Boolean(anchorEl);
const id = open ? "emoji-popover" : undefined;

return (
<>
<Box sx={{ display: "flex", gap: 2, alignItems: "center", width: "100%" }}>
<TextField
{...textFieldProps}
inputRef={inputRef}
value={value}
onChange={(e) => onChange?.(e.target.value)}
value={value.option}
onChange={handleOptionChange}
sx={{ flex: 1 }}
/>
<TextField
value={value.emoji}
InputProps={{
...InputProps,
readOnly: true,
endAdornment: (
<InputAdornment position="end">
<IconButton
Expand All @@ -93,6 +83,7 @@ const EmojiInputPicker: React.FC<EmojiInputPickerProps> = ({
</InputAdornment>
)
}}
sx={{ width: "100px" }}
/>
<Popover
id={id}
Expand Down Expand Up @@ -127,8 +118,8 @@ const EmojiInputPicker: React.FC<EmojiInputPickerProps> = ({
/>
</Paper>
</Popover>
</>
</Box>
);
};

export default EmojiInputPicker;
export default EmojiOptionInput;
2 changes: 1 addition & 1 deletion src/pages/DiscordBot/ClaimRole.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const ClaimRole = () => {
const { mutateAsync: claimRole } = useMutation<any, void, any>({
mutationFn: (claimRoleRequest) => {
return axios
.post(`${environment.apiUrl}/discord//get-role`, claimRoleRequest)
.post(`${environment.apiUrl}/discord/get-role`, claimRoleRequest)
.then((res) => res.data);
}
});
Expand Down
Loading

0 comments on commit c3c8154

Please sign in to comment.