mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-12-28 10:42:25 +08:00
5c8e117800
* Add initial user config modal * Assign user ids * Update session data to hold user ids * Get users list for specific ids * Render user avatar * User update * Refactor user changes * Subscribe to individual user updates * Show users in side panel * Add sidebar to homepage * Don't generate the same color twice in a row * Add documentation notes * Fix tests * Add tests * Keep users in session data * Rename color to hex_color
43 lines
988 B
JavaScript
43 lines
988 B
JavaScript
import { decodeBase64, encodeBase64 } from "./utils";
|
|
|
|
const USER_DATA_COOKIE = "user_data";
|
|
|
|
/**
|
|
* Stores user data in the `"user_data"` cookie.
|
|
*/
|
|
export function storeUserData(userData) {
|
|
const json = JSON.stringify(userData);
|
|
const encoded = encodeBase64(json);
|
|
setCookie(USER_DATA_COOKIE, encoded, 157_680_000); // 5 years
|
|
}
|
|
|
|
/**
|
|
* Loads user data from the `"user_data"` cookie.
|
|
*/
|
|
export function loadUserData() {
|
|
const encoded = getCookieValue(USER_DATA_COOKIE);
|
|
if (encoded) {
|
|
const json = decodeBase64(encoded);
|
|
return JSON.parse(json);
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function getCookieValue(key) {
|
|
const cookie = document.cookie
|
|
.split("; ")
|
|
.find((cookie) => cookie.startsWith(`${key}=`));
|
|
|
|
if (cookie) {
|
|
const value = cookie.replace(`${key}=`, "");
|
|
return value;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function setCookie(key, value, maxAge) {
|
|
const cookie = `${key}=${value};max-age=${maxAge};path=/`;
|
|
document.cookie = cookie;
|
|
}
|