Skip to content

Instantly share code, notes, and snippets.

View binhtran04's full-sized avatar

Binh Tran binhtran04

View GitHub Profile
@binhtran04
binhtran04 / checkout.js
Created December 23, 2021 09:30 — forked from michelarteta/checkout.js
Shopify Adds Custom Attributes to Checkout
const citTag = '123456789';
const store = {
order_attributes: [
'citNumberId'
]
}
const storeOrderData = {
attributes: {
// Type JavaScript here and click "Run Code" or press Ctrl + s
console.log('Hello, world!');
// CHALLENGE 1
function sumFunc(arr) {
// YOUR CODE HERE
let sum = 0
for (let i = 0; i < arr.length; i++) {
sum += arr[i]
@binhtran04
binhtran04 / App.js
Created April 4, 2020 09:28
Multiple providers
const App = () => {
return (
<AuthenticationProvider>
<Router>
<Home path="/" />
<UserProfile path="/myProfile" />
<Dashboard path="/dashboard" />
</Router>
</AuthenticationProvider>
)
@binhtran04
binhtran04 / MoviesContext.js
Created April 3, 2020 14:29
Implement addMovie
import React from 'react';
import { v4 as uuidv4 } from 'uuid';
import { initialMovies } from './initialState';
const MoviesContext = React.createContext();
const ADD_MOVIE = 'ADD_MOVIE';
const MARK_WATCHED_MOVIE = 'MARK_WATCHED_MOVIE';
const moviesReducer = (state, action) => {
switch (action.type) {
@binhtran04
binhtran04 / NewMovie.js
Created April 3, 2020 14:20
NewMovie component
import React from 'react';
import { useMoviesContext } from './MoviesContext';
const getInitialMovieForm = () => {
return {
title: '',
year: '',
};
};
@binhtran04
binhtran04 / MoviesContext.js
Created April 3, 2020 14:03
Implement markWatchedMovie
const MoviesContext = React.createContext();
const MARK_WATCHED_MOVIE = 'MARK_WATCHED_MOVIE';
const moviesReducer = (state, action) => {
switch (action.type) {
case MARK_WATCHED_MOVIE: {
const movies = state.movies.map(movie => {
if (movie.id === action.payload.id) {
return { ...movie, watched: !movie.watched };
}
@binhtran04
binhtran04 / Movie.js
Created April 3, 2020 13:36
Movie component
import React from 'react';
import { useMoviesContext } from './MoviesContext';
export const Movie = ({ movie }) => {
const { markWatchedMovie } = useMoviesContext();
const handleCheckboxChange = () => {
markWatchedMovie(movie.id);
};
@binhtran04
binhtran04 / Movies.js
Created April 3, 2020 13:27
Movies component
import React from 'react';
import { Movie } from './Movie';
import { useMoviesContext } from './MoviesContext';
export const Movies = () => {
const { movies } = useMoviesContext();
return (
<section className="Movies">
<h2>My Movies</h2>
@binhtran04
binhtran04 / App.js
Created April 3, 2020 13:12
Movies App component
import React from 'react';
import { Movies } from './Movies';
import { MoviesProvider } from './MoviesContext';
import { NewMovie } from './NewMovie';
import './App.scss';
export const App = () => {
return (
<div className="App">
<MoviesProvider>
@binhtran04
binhtran04 / MoviesContext.js
Last active April 3, 2020 14:28
Skeleton for MovieContext
/**
initialMovies = [
{
id: uuidv4(),
title: 'The Godfather',
year: 1972,
watched: false,
},
{
id: uuidv4(),