export function setCurrentModule(id) {
  return sequence('setCurrentModule', [
    set(state`editor.currentTabId`, null),
    addTabById(id),
    setCurrentModuleById(id),
  ]);
}
Beispiel #2
0
export function withLoadApp(continueSequence) {
  return sequence(
    'loadApp',
    [
      when(state`hasLoadedApp`),
      {
        true: continueSequence,
        false: [
          set(state`isAuthenticating`, true),
          actions.setJwtFromStorage,
          when(state`jwt`),
          {
            true: [
              parallel([
                sequence('loadUser', [
                  actions.getUser,
                  {
                    success: [
                      set(state`user`, props`user`),
                    ],
                    error: [
                      actions.removeJwtFromStorage,
                      addNotification('登录信息已过期,请重新登录...', 'warning'),
                    ]
                  }
                ]),
                continueSequence,
              ])
            ],
            false: [
              actions.removeJwtFromStorage,
              continueSequence,
            ]
          },
          set(state`hasLoadedApp`, true),
          set(state`isAuthenticating`, false),
        ]
      }
    ]
  )
}
Beispiel #3
0
function changePage(page, continueChain = []) {
  return sequence('change page', [
    set(state`app.menuExpanded`, false),
    set(state`app.page`, page),
    set(state`competition.isPresentation`, false),
    when(props`competitionKey`),
    {
      true: set(state`app.currentCompetition`, props`competitionKey`),
      false: [],
    },
    continueChain,
    setPageView,
  ]);
}
export const closeUserMenu = set(state`userMenuOpen`, false);

export const removeNotification = actions.removeNotification;

export const addNotification = factories.addNotification(
  props`message`,
  props`type`
);

export const forkSandbox = sequence('forkSandbox', [
  factories.track('Fork Sandbox', {}),
  set(state`editor.isForkingSandbox`, true),
  actions.forkSandbox,
  actions.moveModuleContent,
  set(state`editor.sandboxes.${props`sandbox.id`}`, props`sandbox`),
  set(state`editor.currentId`, props`sandbox.id`),
  factories.addNotification('Forked sandbox!', 'success'),
  factories.updateSandboxUrl(props`sandbox`),
  ensurePackageJSON,
  set(state`editor.isForkingSandbox`, false),
]);

export const ensureOwnedSandbox = sequence('ensureOwnedSandbox', [
  when(state`editor.currentSandbox.owned`),
  {
    true: [],
    false: forkSandbox,
  },
]);

export const fetchGitChanges = [
Beispiel #5
0
import { sequence, props, state, string } from 'cerebral';
import { set, when } from 'cerebral/operators';
import { value } from 'providers/Firebase/operators';

export const get10Images = sequence('get 10 images', [
  value(string`images.${state`app.user.uid`}`),
  {
    error: [],
    success: [
      when(props`response.value`),
      { true: set(state`profile.images`, props`response.value`), false: [] },
    ],
  },
]);

export const profileRouted = get10Images;
export function withLoadApp(continueSequence) {
  return sequence('loadApp', [
    when(state`hasLoadedApp`),
    {
      true: continueSequence,
      false: [
        set(state`isAuthenticating`, true),
        actions.setJwtFromStorage,
        actions.listenToConnectionChange,
        actions.setStoredSettings,
        actions.setKeybindings,
        actions.startKeybindings,

        shouldShowThemingOption,
        {
          true: [
            addNotification(
              'You can now use your VSCode theme on CodeSandbox! Check it out in your preferences.',
              'notice',
              60 // a minute
            ),
          ],
          false: [],
        },

        when(state`jwt`),
        {
          true: [
            parallel([
              sequence('loadUser', [
                actions.getUser,
                {
                  success: [
                    set(state`user`, props`user`),
                    actions.setPatronPrice,
                    actions.setSignedInCookie,
                    actions.connectWebsocket,
                    initializeNotifications,
                  ],
                  error: [
                    addNotification(
                      'Your session seems to be expired, please log in again...',
                      'error'
                    ),
                    actions.removeJwtFromStorage,
                  ],
                },
              ]),
              continueSequence,
            ]),
          ],
          false: [
            actions.removeJwtFromStorage, // To delete the signedIn cookie as well, to be sure
            continueSequence,
          ],
        },
        set(state`hasLoadedApp`, true),
        set(state`isAuthenticating`, false),
        actions.getContributors,
      ],
    },
  ]);
}