How to use contexts - 10 common examples

To help you get started, we’ve selected a few contexts examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mikey1384 / twinkle-network / source / containers / App / index.js View on Github external
function App({ location, history }) {
  const {
    user: {
      actions: { onCloseSigninModal, onInitSession, onLogout }
    },
    requestHelpers: { auth, initSession, uploadFileOnChat }
  } = useAppContext();
  const { signinModalShown, username } = useMyState();
  const {
    actions: {
      onPostFileUploadStatus,
      onPostUploadComplete,
      onResetChat,
      onSendFirstDirectMessage,
      onUpdateClientToApiServerProgress
    }
  } = useChatContext();
  const {
    actions: { onInitContent }
  } = useContentContext();
  const {
    state: { updateDetail, updateNoticeShown }
  } = useNotiContext();
github mikey1384 / twinkle-network / source / containers / Management / Main.js View on Github external
export default function Main() {
  const { userId, managementLevel } = useMyState();
  const canManage = useMemo(() => managementLevel > 1, [managementLevel]);
  const {
    requestHelpers: { loadAccountTypes, loadModerators }
  } = useAppContext();
  const {
    state: { accountTypes, accountTypesLoaded, moderators, moderatorsLoaded },
    actions: { onLoadAccountTypes, onLoadModerators }
  } = useManagementContext();
  const [accountTypeModalTarget, setAccountTypeModalTarget] = useState(null);
  const [moderatorModalTarget, setModeratorModalTarget] = useState(null);
  const [addAccountTypeModalShown, setAddAccountTypeModalShown] = useState(
    false
  );
  const [addModeratorModalShown, setAddModeratorModalShown] = useState(false);
  useEffect(() => {
    initModerators();
    initAccountTypes();
    async function initModerators() {
      const data = await loadModerators();
      onLoadModerators(data);
github mikey1384 / twinkle-network / source / containers / App / index.js View on Github external
const {
    user: {
      actions: { onCloseSigninModal, onInitSession, onLogout }
    },
    requestHelpers: { auth, initSession, uploadFileOnChat }
  } = useAppContext();
  const { signinModalShown, username } = useMyState();
  const {
    actions: {
      onPostFileUploadStatus,
      onPostUploadComplete,
      onResetChat,
      onSendFirstDirectMessage,
      onUpdateClientToApiServerProgress
    }
  } = useChatContext();
  const {
    actions: { onInitContent }
  } = useContentContext();
  const {
    state: { updateDetail, updateNoticeShown }
  } = useNotiContext();
  const {
    state: { pageVisible },
    actions: { onChangePageVisibility }
  } = useViewContext();
  const [mobileMenuShown, setMobileMenuShown] = useState(false);
  const visibilityChangeRef = useRef(null);
  const hiddenRef = useRef(null);
  const authRef = useRef(null);
  const mounted = useRef(true);
github mikey1384 / twinkle-network / source / containers / App / index.js View on Github external
},
    requestHelpers: { auth, initSession, uploadFileOnChat }
  } = useAppContext();
  const { signinModalShown, username } = useMyState();
  const {
    actions: {
      onPostFileUploadStatus,
      onPostUploadComplete,
      onResetChat,
      onSendFirstDirectMessage,
      onUpdateClientToApiServerProgress
    }
  } = useChatContext();
  const {
    actions: { onInitContent }
  } = useContentContext();
  const {
    state: { updateDetail, updateNoticeShown }
  } = useNotiContext();
  const {
    state: { pageVisible },
    actions: { onChangePageVisibility }
  } = useViewContext();
  const [mobileMenuShown, setMobileMenuShown] = useState(false);
  const visibilityChangeRef = useRef(null);
  const hiddenRef = useRef(null);
  const authRef = useRef(null);
  const mounted = useRef(true);

  useEffect(() => {
    mounted.current = true;
    return function cleanUp() {
github mikey1384 / twinkle-network / source / components / VideoPlayer.js View on Github external
style = {},
  uploader,
  videoCode,
  videoId
}) {
  const {
    requestHelpers: {
      addVideoView,
      checkXPEarned,
      fetchVideoThumbUrl,
      updateCurrentlyWatching,
      updateUserXP,
      updateTotalViewDuration,
      updateVideoXPEarned
    }
  } = useAppContext();
  const { profileTheme, twinkleXP, userId } = useMyState();
  const {
    state: {
      videos: { currentVideoSlot }
    },
    actions: { onEmptyCurrentVideoSlot, onFillCurrentVideoSlot }
  } = useExploreContext();
  const {
    state: { pageVisible }
  } = useViewContext();
  const {
    actions: {
      onChangeUserXP,
      onSetVideoImageUrl,
      onSetVideoStarted,
      onSetVideoXpEarned,
github mikey1384 / twinkle-network / source / containers / Home / index.js View on Github external
export default function Home({ history, location }) {
  const {
    requestHelpers: { uploadProfilePic }
  } = useAppContext();
  const {
    actions: { onUploadProfilePic }
  } = useContentContext();
  const { userId } = useMyState();
  const [alertModalShown, setAlertModalShown] = useState(false);
  const [imageEditModalShown, setImageEditModalShown] = useState(false);
  const [imageUri, setImageUri] = useState(null);
  const [processing, setProcessing] = useState(false);

  return (
    
      <div>
        <div>
           setAlertModalShown(true)}
            onLoadImage={upload =&gt; {
              setImageEditModalShown(true);
              setImageUri(upload.target.result);</div></div>
github mikey1384 / twinkle-network / source / containers / Profile / Body / Home / index.js View on Github external
onDeleteComment,
      onEditComment,
      onEditRewardComment,
      onLikeComment,
      onLoadComments,
      onLoadMoreComments,
      onLoadMoreReplies,
      onLoadRepliesOfReply,
      onUpdateStatusMsg,
      onUploadComment,
      onUploadReply,
      onRemoveStatusMsg,
      onUpdateGreeting,
      onUpdateBio
    }
  } = useContentContext();
  const {
    state: { editedStatusMsg, editedStatusColor },
    actions: { onSetEditedStatusColor, onSetEditedStatusMsg }
  } = useInputContext();
  const {
    commentsLoaded,
    email,
    emailVerified,
    greeting,
    id,
    joinDate,
    lastActive,
    online,
    statusMsg,
    profileFirstRow,
    profileSecondRow,
github mikey1384 / twinkle-network / source / containers / VideoPage / Details / index.js View on Github external
onSetRewardLevel,
  stars,
  timeStamp,
  videoId,
  videoViews
}) {
  const {
    authLevel,
    canDelete,
    canEdit,
    canEditPlaylists,
    canStar
  } = useMyState();
  const {
    actions: { onSetIsEditing, onSetXpRewardInterfaceShown }
  } = useContentContext();
  const {
    state: inputState,
    actions: { onSetEditForm }
  } = useInputContext();
  const { isEditing, xpRewardInterfaceShown } = useContentState({
    contentType: 'video',
    contentId: videoId
  });
  const [titleHovered, setTitleHovered] = useState(false);
  const TitleRef = useRef(null);
  const RewardInterfaceRef = useRef(null);

  useEffect(() => {
    if (!inputState['edit' + 'video' + videoId]) {
      onSetEditForm({
        contentId: videoId,
github mikey1384 / twinkle-network / source / components / Comments / Replies / Reply.js View on Github external
deleteReply,
  loadRepliesOfReply,
  parent,
  reply,
  reply: { likes = [], stars = [], uploader },
  rootContent,
  submitReply,
  subject
}) {
  const {
    requestHelpers: { editContent, loadReplies }
  } = useAppContext();
  const { authLevel, canDelete, canEdit, canStar, userId } = useMyState();
  const {
    actions: { onSetIsEditing, onSetXpRewardInterfaceShown }
  } = useContentContext();
  const { deleted, isEditing, xpRewardInterfaceShown } = useContentState({
    contentType: 'comment',
    contentId: reply.id
  });
  const {
    onAttachStar,
    onEditDone,
    onLikeClick,
    onRewardCommentEdit
  } = useContext(LocalContext);
  const [userListModalShown, setUserListModalShown] = useState(false);
  const [confirmModalShown, setConfirmModalShown] = useState(false);
  const ReplyInputAreaRef = useRef(null);
  const RewardInterfaceRef = useRef(null);
  const userIsUploader = userId === uploader.id;
  const userIsHigherAuth = authLevel > uploader.authLevel;
github mikey1384 / twinkle-network / source / components / VideoPlayer.js View on Github external
const {
    state: { pageVisible }
  } = useViewContext();
  const {
    actions: {
      onChangeUserXP,
      onSetVideoImageUrl,
      onSetVideoStarted,
      onSetVideoXpEarned,
      onSetVideoXpJustEarned,
      onSetVideoXpLoaded,
      onSetVideoXpProgress,
      onSetXpVideoWatchTime,
      onSetVideoCurrentTime
    }
  } = useContentContext();
  const {
    currentTime = 0,
    started,
    xpLoaded,
    xpEarned,
    justEarned,
    imageUrl = '',
    progress = 0,
    watchTime = 0,
    isEditing
  } = useContentState({ contentType: 'video', contentId: videoId });
  const [playing, setPlaying] = useState(false);
  const [alreadyEarned, setAlreadyEarned] = useState(false);
  const [startingPosition, setStartingPosition] = useState(0);
  const [timeAt, setTimeAt] = useState(0);
  const maxRequiredDuration = 250;

contexts

ISC
Latest version published 8 years ago

Package Health Score

40 / 100
Full package analysis