SearchStore.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { types } from "mobx-state-tree";
  2. export const ResultItem = types.model("ResultItem", {
  3. id: types.identifier(types.number),
  4. folderId: types.optional(types.number, 0),
  5. title: types.string,
  6. url: types.string,
  7. icon: types.string,
  8. folderTitle: types.optional(types.string, "")
  9. });
  10. export const SearchResultSection = types
  11. .model("SearchResultSection", {
  12. id: types.identifier(),
  13. title: types.string,
  14. icon: types.string,
  15. expanded: types.boolean,
  16. items: types.array(ResultItem)
  17. })
  18. .actions(self => ({
  19. toggle() {
  20. self.expanded = !self.expanded;
  21. for (let i = 0; i < 100; i++) {
  22. self.items.push(
  23. ResultItem.create({
  24. id: i,
  25. title: "Dashboard " + self.items.length,
  26. icon: "gicon gicon-dashboard",
  27. url: "asd"
  28. })
  29. );
  30. }
  31. }
  32. }));
  33. export const SearchStore = types
  34. .model("SearchStore", {
  35. sections: types.array(SearchResultSection)
  36. })
  37. .actions(self => ({
  38. query() {
  39. for (let i = 0; i < 100; i++) {
  40. self.sections.push(
  41. SearchResultSection.create({
  42. id: "starred" + i,
  43. title: "starred",
  44. icon: "fa fa-fw fa-star-o",
  45. expanded: false,
  46. items: []
  47. })
  48. );
  49. }
  50. }
  51. }));