<commit_before>import { fromJS, List } from 'immutable';

import { setUpSocket, getNextVideoId, getPreviousVideoId } from './utils';

import {
  SHOW_NOTIFICATION,
  CLOSE_NOTIFICATION,
  SEND_INIT_INFO,
  SET_CONNECTED,
  SET_SOCKET,
  TOGGLE_SIDEBAR,
  TOGGLE_SEARCH,
  SET_PLAYER,
  SET_YOUTUBE_STATE,
  SET_IS_PLAYING,

  SEND_ADD_VIDEO_ITEM,
  SEND_DELETE_VIDEO_ITEM,
  SEND_PLAY_YOUTUBE,
  SEND_PLAY_NEXT_VIDEO,
  SEND_PLAY_PREV_VIDEO,
  SEND_PAUSE_YOUTUBE,
  SEND_RESUME_YOUTUBE,
  SEND_SYNC_PLAY_TIME,

  ADD_VIDEO_ITEM,
  DELETE_VIDEO_ITEM,
  PLAY_YOUTUBE,
  PLAY_NEXT_VIDEO,
  PLAY_PREV_VIDEO,
  PAUSE_YOUTUBE,
  RESUME_YOUTUBE,
  SYNC_PLAY_TIME,
} from './constants';

let socket = null;

const initialState = fromJS({
  isConnected: false,
  showSidebar: true,
  showSearch: true,
  player: null,
  playlist: [],
  videoId: '',
  isPlaying: false,
  isSending: {
    roomName: false,
    addVideo: false,
    deleteVideo: false,
    play: false,
    playNext: false,
    playPrevious: false,
    pause: false,
    resume: false,
    syncTime: false,
  },
  notification: {
    open: false,
    message: 'connecting...',
  },
});

function youtubeReducer(state = initialState, { type, payload }) {
  switch (type) {
    case SHOW_NOTIFICATION:
      return state
        .setIn(['notification', 'open'], true)
        .setIn(['notification', 'message'], payload);
    case CLOSE_NOTIFICATION:
      return state.setIn(['notification', 'open'], false);
    case SET_CONNECTED:
      return state.set('isConnected', payload);

    case SET_SOCKET: {
      const { roomName, dispatch } = payload;
      socket = setUpSocket(roomName, dispatch);
      return state;
    }

    case TOGGLE_SIDEBAR:
      return state.set('showSidebar', !state.get('showSidebar'));
    case TOGGLE_SEARCH:
      return state.set('showSearch', !state.get('showSearch'));
    case SET_PLAYER:
      return state.set('player', payload);
    case SET_YOUTUBE_STATE:
      return state
        .set('playlist', new List(payload.playlist))
        .setIn(['isSending', 'roomName'], false);
    case SET_IS_PLAYING:<commit_msg>Set current playing video id during initialization<commit_after>import { fromJS, List } from 'immutable';

import { setUpSocket, getNextVideoId, getPreviousVideoId } from './utils';

import {
  SHOW_NOTIFICATION,
  CLOSE_NOTIFICATION,
  SEND_INIT_INFO,
  SET_CONNECTED,
  SET_SOCKET,
  TOGGLE_SIDEBAR,
  TOGGLE_SEARCH,
  SET_PLAYER,
  SET_YOUTUBE_STATE,
  SET_IS_PLAYING,

  SEND_ADD_VIDEO_ITEM,
  SEND_DELETE_VIDEO_ITEM,
  SEND_PLAY_YOUTUBE,
  SEND_PLAY_NEXT_VIDEO,
  SEND_PLAY_PREV_VIDEO,
  SEND_PAUSE_YOUTUBE,
  SEND_RESUME_YOUTUBE,
  SEND_SYNC_PLAY_TIME,

  ADD_VIDEO_ITEM,
  DELETE_VIDEO_ITEM,
  PLAY_YOUTUBE,
  PLAY_NEXT_VIDEO,
  PLAY_PREV_VIDEO,
  PAUSE_YOUTUBE,
  RESUME_YOUTUBE,
  SYNC_PLAY_TIME,
} from './constants';

let socket = null;

const initialState = fromJS({
  isConnected: false,
  showSidebar: true,
  showSearch: true,
  player: null,
  playlist: [],
  videoId: '',
  isPlaying: false,
  isSending: {
    roomName: false,
    addVideo: false,
    deleteVideo: false,
    play: false,
    playNext: false,
    playPrevious: false,
    pause: false,
    resume: false,
    syncTime: false,
  },
  notification: {
    open: false,
    message: 'connecting...',
  },
});

function youtubeReducer(state = initialState, { type, payload }) {
  switch (type) {
    case SHOW_NOTIFICATION:
      return state
        .setIn(['notification', 'open'], true)
        .setIn(['notification', 'message'], payload);
    case CLOSE_NOTIFICATION:
      return state.setIn(['notification', 'open'], false);
    case SET_CONNECTED:
      return state.set('isConnected', payload);

    case SET_SOCKET: {
      const { roomName, dispatch } = payload;
      socket = setUpSocket(roomName, dispatch);
      return state;
    }

    case TOGGLE_SIDEBAR:
      return state.set('showSidebar', !state.get('showSidebar'));
    case TOGGLE_SEARCH:
      return state.set('showSearch', !state.get('showSearch'));
    case SET_PLAYER:
      return state.set('player', payload);
    case SET_YOUTUBE_STATE:
      return state
        .set('playlist', new List(payload.playlist))
        .set('videoId', payload.currentPlayingVideoId)
        .setIn(['isSending', 'roomName'], false);
    case SET_IS_PLAYING:
{'fraction_non_alphanumeric': 0.11345707656612529, 'fraction_numerical': 0.0, 'mean_word_length': 3.6605405405405405, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7227672', 'n_tokens_mistral': 1563, 'n_tokens_neox': 1559, 'n_words': 303}