mirror of
https://github.com/status-im/spiff-arena.git
synced 2025-03-01 18:00:42 +00:00
use a sha256 value as the id of the page when checking active-users w/ burnettk (#356)
Co-authored-by: jasquat <jasquat@users.noreply.github.com>
This commit is contained in:
parent
5ffb3e5ae5
commit
90bfc53380
@ -1,36 +1,51 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
import HttpService from '../services/HttpService';
|
import HttpService from '../services/HttpService';
|
||||||
import {
|
|
||||||
encodeBase64,
|
|
||||||
refreshAtInterval,
|
|
||||||
REFRESH_TIMEOUT_SECONDS,
|
|
||||||
} from '../helpers';
|
|
||||||
import { User } from '../interfaces';
|
import { User } from '../interfaces';
|
||||||
|
import { refreshAtInterval, REFRESH_TIMEOUT_SECONDS } from '../helpers';
|
||||||
|
|
||||||
|
async function sha256(message: string) {
|
||||||
|
// encode as UTF-8
|
||||||
|
const msgBuffer = new TextEncoder().encode(message);
|
||||||
|
|
||||||
|
// hash the message
|
||||||
|
const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer);
|
||||||
|
|
||||||
|
// convert ArrayBuffer to Array
|
||||||
|
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
||||||
|
|
||||||
|
// convert bytes to hex string
|
||||||
|
return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
|
||||||
|
}
|
||||||
|
|
||||||
export default function ActiveUsers() {
|
export default function ActiveUsers() {
|
||||||
// Handles getting and displaying active users.
|
// Handles getting and displaying active users.
|
||||||
const [activeUsers, setActiveUsers] = useState<User[]>([]);
|
const [activeUsers, setActiveUsers] = useState<User[]>([]);
|
||||||
|
|
||||||
const lastVisitedIdentifier = encodeBase64(window.location.pathname);
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const updateActiveUsers = () => {
|
const updateActiveUsers = () => {
|
||||||
HttpService.makeCallToBackend({
|
const makeCall = (lastVisitedIdentifier: any) => {
|
||||||
path: `/active-users/updates/${lastVisitedIdentifier}`,
|
HttpService.makeCallToBackend({
|
||||||
successCallback: setActiveUsers,
|
path: `/active-users/updates/${lastVisitedIdentifier}`,
|
||||||
httpMethod: 'POST',
|
successCallback: setActiveUsers,
|
||||||
});
|
httpMethod: 'POST',
|
||||||
};
|
});
|
||||||
|
};
|
||||||
const unregisterUser = () => {
|
sha256(window.location.pathname).then(makeCall);
|
||||||
HttpService.makeCallToBackend({
|
|
||||||
path: `/active-users/unregister/${lastVisitedIdentifier}`,
|
|
||||||
successCallback: setActiveUsers,
|
|
||||||
httpMethod: 'POST',
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
updateActiveUsers();
|
updateActiveUsers();
|
||||||
|
|
||||||
|
const unregisterUser = () => {
|
||||||
|
const makeCall = (lastVisitedIdentifier: any) => {
|
||||||
|
HttpService.makeCallToBackend({
|
||||||
|
path: `/active-users/unregister/${lastVisitedIdentifier}`,
|
||||||
|
successCallback: setActiveUsers,
|
||||||
|
httpMethod: 'POST',
|
||||||
|
});
|
||||||
|
};
|
||||||
|
sha256(window.location.pathname).then(makeCall);
|
||||||
|
};
|
||||||
|
|
||||||
return refreshAtInterval(
|
return refreshAtInterval(
|
||||||
15,
|
15,
|
||||||
REFRESH_TIMEOUT_SECONDS,
|
REFRESH_TIMEOUT_SECONDS,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user