Skip to content
Snippets Groups Projects
Select Git revision
  • aac6d1d3cb6ab603ac90ef62253fe11ace92db8a
  • master default protected
  • feat/new-image-formats
  • clickable-select-chevron
  • 2.20.0
  • 2.19.0
  • 2.18.0
  • 2.17.0
  • 2.16.1
  • 2.16.0
  • 2.15.0
  • 2.14.0
  • 2.13.0
  • 2.12.1
  • 2.11.0
  • 2.10.0
  • 2.9.1
  • 2.9.0
  • 2.8.0
  • 2.7.1
  • 2.7.0
  • 2.6.0
  • 2.5.2
  • 2.5.1
24 results

05-standard-container.mustache

Blame
  • 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));
    });