Skip to content

Commit

Permalink
update to new api
Browse files Browse the repository at this point in the history
  • Loading branch information
stCarolas committed Mar 1, 2024
1 parent ee84104 commit 008de27
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 46 deletions.
16 changes: 9 additions & 7 deletions src/components/DonatersTopList/DonatersTopList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default function DonatersTopList({}: {}) {
function updateDonaters() {
axios
.get(
`${process.env.REACT_APP_API_ENDPOINT}/recipient/${recipientId}/donaters?period=${period}`,
`${process.env.REACT_APP_RECIPIENT_API_ENDPOINT}/recipients/${recipientId}/donaters?period=${period}`,
)
.then((response) => response.data)
.then((data) => {
Expand All @@ -58,16 +58,18 @@ export default function DonatersTopList({}: {}) {
type === "Last"
? map
: new Map(
[...map.entries()].sort((a, b) => b[1].amount - a[1].amount),
[...map.entries()].sort((a, b) => b[1].major - a[1].major),
);
setDonaters(sortedMap);
});
}

useEffect(() => {
subscribe(widgetId, conf.topic.alerts, (message) => {
updateDonaters();
message.ack();
setTimeout(() => {
updateDonaters();
message.ack();
}, 3000);
});
setupCommandListener(widgetId, () => navigate(0));
updateDonaters();
Expand Down Expand Up @@ -129,7 +131,7 @@ export default function DonatersTopList({}: {}) {
donaters.size > 0 &&
Array.from(donaters.keys()).map((donater) => (
<span key={donater} style={textStyle} className="donater">
{donater} - {donaters.get(donater).amount}{" "}
{donater} - {donaters.get(donater).major}{" "}
{donaters.get(donater).currency}{" "}
</span>
))}
Expand All @@ -147,7 +149,7 @@ export default function DonatersTopList({}: {}) {
.slice(0, topsize)
.map((donater) => (
<div key={donater} style={textStyle} className="donater">
{donater} - {donaters.get(donater).amount}{" "}
{donater} - {donaters.get(donater).major}{" "}
{donaters.get(donater).currency}{" "}
</div>
))}
Expand All @@ -166,7 +168,7 @@ export default function DonatersTopList({}: {}) {
.slice(0, topsize)
.map((donater) => (
<div key={donater} style={textStyle} className="donater">
{donater} - {donaters.get(donater).amount}{" "}
{donater} - {donaters.get(donater).major}{" "}
{donaters.get(donater).currency}{" "}
</div>
))}
Expand Down
2 changes: 1 addition & 1 deletion src/components/DonationTimer/DonationTimer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function DonationTimer({}: {}) {
}
axios
.get(
`${process.env.REACT_APP_API_ENDPOINT}/payment?recipientId=${recipientId}`,
`${process.env.REACT_APP_API_ENDPOINT}/payments`,
)
.then((response) => response.data)
.then((data) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/MediaWidget/MediaWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function MediaWidget({}: {}) {
},
};
setupCommandListener(widgetId, () => navigate(0));
paymentPageConfig.current = new PaymentPageConfig();
paymentPageConfig.current = new PaymentPageConfig(recipientId);
playlistController.current = new PlaylistController(
recipientId,
widgetId,
Expand Down
4 changes: 2 additions & 2 deletions src/components/MediaWidget/PaymentPageConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export class PaymentPageConfig {
requestsDisabledPermanently = false;
requestCost = 100;

constructor() {
constructor(recipientId: string) {
log.debug("Loading PaymentPageConfig");
axios
.get(`${process.env.REACT_APP_CONFIG_API_ENDPOINT}/config/paymentpage`)
.get(`${process.env.REACT_APP_CONFIG_API_ENDPOINT}/config/paymentpage?ownerId=${recipientId}`)
.then((data) => data.data)
.then((json) => {
this.config = json;
Expand Down
32 changes: 5 additions & 27 deletions src/components/MediaWidget/PlaylistController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ export class PlaylistController {

axios
.get(
`${process.env.REACT_APP_API_ENDPOINT}/media?recipientId=${recipientId}`,
`${process.env.REACT_APP_MEDIA_API_ENDPOINT}/media/video`,
)
.then((response) => {
let songs = response.data;
songs = songs.map(
(element: { url: string; id: string; title: string }) => {
(element: { url: string; id: string; title: string; owner: string }) => {
return {
src: element.url,
type: "video/youtube",
id: uuidv4(),
originId: element.id,
owner: "Аноним",
owner: element.owner,
title: element.title,
};
},
);
return fillSongData(recipientId, songs);
return songs;
})
.then((playlist) => {
.then((playlist: Song[]) => {
playlist.forEach((song) => this.current.addSong(song));
});

Expand Down Expand Up @@ -119,25 +119,3 @@ export class PlaylistController {
}
}
}

async function fillSongData(recipientId: string, playlist: Song[]) {
log.info(`Trying to find songs for ${recipientId}`);
let response = await axios.get(
`${process.env.REACT_APP_API_ENDPOINT}/payment?recipientId=${recipientId}`,
);
let updatedPlaylist = playlist;
response.data.forEach(
(item: { attachments: (string | null)[]; senderName: string | null }) =>
item.attachments.forEach((attach: string | null) => {
updatedPlaylist = updatedPlaylist.map((song) => {
if (song.originId === attach) {
song.owner = item.senderName ? item.senderName : "Аноним";
return song;
} else {
return song;
}
});
}),
);
return updatedPlaylist;
}
9 changes: 5 additions & 4 deletions src/components/MediaWidget/api.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import axios from "axios";

export function markListened(id:string) {
export function markListened(id: string) {
try {
axios
.patch(`${process.env.REACT_APP_API_ENDPOINT}/media/${id}`, {
listened: true,
})
.patch(
`${process.env.REACT_APP_MEDIA_API_ENDPOINT}/media/video/${id}`,
{},
)
.catch(function (error) {
console.log(error);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default function PaymentPageConfigComponent({}: {}) {
};

useEffect(() => {
paymentPageConfig.current = new PaymentPageConfig();
paymentPageConfig.current = new PaymentPageConfig(recipientId);
}, [recipientId]);

useEffect(() => {
Expand Down
5 changes: 3 additions & 2 deletions src/components/Payments/Payments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ function Payments({}: {}) {
const attachQueryString = json
.reduce((attachmentIds, payment) => {
const paymentAttachIds = payment.attachments
.reduce(
?.reduce(
(paymentAttachmentIds, attach) =>
`${paymentAttachmentIds},${attach}`,
"",
)
.substring(1);
?.substring(1) ?? "";
return `${attachmentIds},${paymentAttachIds}`;
}, "")
.substring(1);
Expand Down Expand Up @@ -167,6 +167,7 @@ function Payments({}: {}) {
}

function paymentList(data) {
log.debug(`rendering ${JSON.stringify(data)}`);
const nicknameFontSize = findSetting(settings, "nicknameFontSize", "24px");
const nicknameStyle = nicknameFontSize
? { fontSize: nicknameFontSize + "px" }
Expand Down
2 changes: 1 addition & 1 deletion src/logic/voice/VoiceController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class VoiceController {
private async voiceByGoogle(message: string): Promise<ArrayBuffer> {
let body = {
input: {
ssml: '<speak><break time="1s"/>' + message + ".</speak>",
ssml: '<speak>' + message + ".</speak>",
},
voice: {
languageCode: "ru-RU",
Expand Down

0 comments on commit 008de27

Please sign in to comment.