Select Git revision
05-standard-container.mustache
stores.js 8.20 KiB
import keyBy from "lodash/keyBy";
import memoize from "lodash/memoize";
import property from "lodash/property";
import { Store } from "pullstate";
import { filterPosts } from "utils";
/** @type {CF2021.AuthStorePayload} */
const authStoreInitial = {
isAuthenticated: false,
groupMappings: [],
};
export const AuthStore = new Store(authStoreInitial);
/** @type {CF2021.AnnouncementStorePayload} */
const announcementStoreInitial = {
items: [
{
id: "1",
content:
"Shizz fo shizzle mah nizzle fo rizzle, mah home g-dizzle, gravida vizzle, arcu. Pellentesque crunk tortizzle. Sed erizzle. Black izzle sheezy telliv.",
datetime: new Date(),
seen: false,
type: "rejected-procedure-proposal",
},
{
id: "2",
content:
"Shizz fo shizzle mah nizzle fo rizzle, mah home g-dizzle, gravida vizzle, arcu. Pellentesque crunk tortizzle. Sed erizzle. Black izzle sheezy telliv.",
datetime: new Date(),
seen: false,
type: "accepted-procedure-proposal",
},
{
id: "3",
content:
"Shizz fo shizzle mah nizzle fo rizzle, mah home g-dizzle, gravida vizzle, arcu. Pellentesque crunk tortizzle. Sed erizzle. Black izzle sheezy telliv.",
datetime: new Date(),
seen: true,
type: "suggested-procedure-proposal",
},
{
id: "4",
content:
"Shizz fo shizzle mah nizzle fo rizzle, mah home g-dizzle, gravida vizzle, arcu. Pellentesque crunk tortizzle. Sed erizzle. Black izzle sheezy telliv.",
datetime: new Date(),
seen: true,
type: "voting",
},
{
id: "5",
content:
"Shizz fo shizzle mah nizzle fo rizzle, mah home g-dizzle, gravida vizzle, arcu. Pellentesque crunk tortizzle. Sed erizzle. Black izzle sheezy telliv.",
datetime: new Date(),
seen: true,
type: "announcement",
},
{
id: "6",
content:
"Shizz fo shizzle mah nizzle fo rizzle, mah home g-dizzle, gravida vizzle, arcu. Pellentesque crunk tortizzle. Sed erizzle. Black izzle sheezy telliv.",
datetime: new Date(),
seen: true,
type: "user-ban",
},
],
};
export const AnnouncementStore = new Store(announcementStoreInitial);
const allPosts = [
{
id: "1",
content:
"Shizz fo shizzle mah nizzle fo rizzle, mah home g-dizzle, gravida vizzle, arcu. Pellentesque crunk tortizzle. Sed erizzle. Black izzle sheezy telliv.",
datetime: new Date(),
author: {
name: "John Doe",
group: "cf",
},
ranking: {
likes: 0,
dislikes: 0,
score: 0,
myVote: "none",
},
seen: false,
archived: false,
type: "post",
},
{
id: "2",
content:
"Shizz fo shizzle mah nizzle fo rizzle, mah home g-dizzle, gravida vizzle, arcu. Pellentesque crunk tortizzle. Sed erizzle. Black izzle sheezy telliv.",
datetime: new Date(),
author: {
name: "John Doe",
group: "cf",
},
ranking: {
likes: 1,
dislikes: 0,
score: 1,
myVote: "none",
},
seen: false,
archived: false,
type: "post",
},
{
id: "3",
content:
"Shizz fo shizzle mah nizzle fo rizzle, mah home g-dizzle, gravida vizzle, arcu. Pellentesque crunk tortizzle. Sed erizzle. Black izzle sheezy telliv.",
datetime: new Date(),
author: {
name: "John Doe",
group: "cf",
},
ranking: {
likes: 5,
dislikes: 5,
score: 0,
myVote: "none",
},
seen: true,
archived: false,
type: "post",
},
{
id: "4",
content:
"Shizz fo shizzle mah nizzle fo rizzle, mah home g-dizzle, gravida vizzle, arcu. Pellentesque crunk tortizzle. Sed erizzle. Black izzle sheezy telliv.",
datetime: new Date(),
author: {
name: "John Doe",
group: "KS Pardubický kraj",
},
ranking: {
likes: 0,
dislikes: 10,
score: -10,
myVote: "none",
},
seen: true,
archived: false,
type: "post",
},
{
id: "5",
content:
"Shizz fo shizzle mah nizzle fo rizzle, mah home g-dizzle, gravida vizzle, arcu. Pellentesque crunk tortizzle. Sed erizzle. Black izzle sheezy telliv.",
datetime: new Date(),
author: {
name: "John Doe",
group: "KS Pardubický kraj",
},
ranking: {
likes: 1,
dislikes: 1,
score: 0,
myVote: "none",
},
seen: true,
archived: false,
type: "post",
},
{
id: "6",
content:
"Shizz fo shizzle mah nizzle fo rizzle, mah home g-dizzle, gravida vizzle, arcu. Pellentesque crunk tortizzle. Sed erizzle. Black izzle sheezy telliv.",
datetime: new Date(),
author: {
name: "John Doe",
group: "KS Pardubický kraj",
},
ranking: {
likes: 5,
dislikes: 3,
score: 2,
myVote: "none",
},
seen: true,
archived: true,
type: "post",
},
{
id: "7",
content:
"Shizz fo shizzle mah nizzle fo rizzle, mah home g-dizzle, gravida vizzle, arcu. Pellentesque crunk tortizzle. Sed erizzle. Black izzle sheezy telliv.",
datetime: new Date(),
author: {
name: "John Doe",
group: "KS Pardubický kraj",
},
ranking: {
likes: 5,
dislikes: 8,
score: -3,
myVote: "none",
},
seen: true,
archived: true,
type: "procedure-proposal",
state: "pending",
},
{
id: "8",
content:
"Shizz fo shizzle mah nizzle fo rizzle, mah home g-dizzle, gravida vizzle, arcu. Pellentesque crunk tortizzle. Sed erizzle. Black izzle sheezy telliv.",
datetime: new Date(),
author: {
name: "John Doe",
group: "KS Pardubický kraj",
},
ranking: {
likes: 2,
dislikes: 1,
score: 1,
myVote: "like",
},
seen: true,
archived: false,
type: "procedure-proposal",
state: "announced",
historyLog: [
{
attribute: "content",
datetime: new Date(),
newValue: "Lemme know",
originator: "chairman",
},
],
},
{
id: "9",
content:
"Shizz fo shizzle mah nizzle fo rizzle, mah home g-dizzle, gravida vizzle, arcu. Pellentesque crunk tortizzle. Sed erizzle. Black izzle sheezy telliv.",
datetime: new Date(),
author: {
name: "John Doe",
group: "KS Pardubický kraj",
},
ranking: {
likes: 5,
dislikes: 0,
score: 5,
myVote: "dislike",
},
seen: true,
archived: false,
type: "procedure-proposal",
state: "accepted",
},
{
id: "10",
content:
"Shizz fo shizzle mah nizzle fo rizzle, mah home g-dizzle, gravida vizzle, arcu. Pellentesque crunk tortizzle. Sed erizzle. Black izzle sheezy telliv.",
datetime: new Date(),
author: {
name: "John Doe",
group: "KS Pardubický kraj",
},
ranking: {
likes: 5,
dislikes: 8,
score: -3,
myVote: "none",
},
seen: true,
archived: false,
type: "procedure-proposal",
state: "rejected",
},
{
id: "11",
content:
"Shizz fo shizzle mah nizzle fo rizzle, mah home g-dizzle, gravida vizzle, arcu. Pellentesque crunk tortizzle. Sed erizzle. Black izzle sheezy telliv.",
datetime: new Date(),
author: {
name: "John Doe",
group: "KS Pardubický kraj",
},
ranking: {
likes: 10,
dislikes: 1,
score: 9,
myVote: "none",
},
seen: true,
archived: true,
type: "procedure-proposal",
state: "rejected-by-chairman",
},
];
const initialPostFilters = {
flags: "all",
sort: "byDate",
type: "all",
};
const filteredPosts = filterPosts(initialPostFilters, allPosts);
/** @type {CF2021.PostStorePayload} */
const postStoreInitial = {
items: keyBy(allPosts, property("id")),
itemCount: allPosts.length,
window: {
items: filteredPosts.map(property("id")),
itemCount: filteredPosts.length,
page: 1,
perPage: 5,
},
filters: initialPostFilters,
};
export const PostStore = new Store(postStoreInitial);
export const getGroupByCode = memoize(
(groupMappings, groupCode) => {
return groupMappings.find((gm) => gm.code === groupCode);
},
(groupMappings, groupCode) => [groupMappings, groupCode]
);
export const getGroupsByCode = memoize((groupMappings, groupCodes) => {
return groupCodes.map((code) => getGroupByCode(groupMappings, code));
});