Skip to content

Instantly share code, notes, and snippets.

View sonangrai's full-sized avatar
🏠
Working from home

Sonahang Rai sonangrai

🏠
Working from home
View GitHub Profile
@sonangrai
sonangrai / shopify-functions.MD
Created July 30, 2024 08:59
Shopify Functions Guide
  1. Generate the extenions with command. npm run generate extensions
  2. Generating does not create app function in shopify admin so we need to create it from gql mutations. i. Check functions with the below query.
    query GetFunctions{
      shopifyFunctions(first: 25) {
        nodes {
          app {
            title
    

}

@sonangrai
sonangrai / Toast.tsx
Last active July 31, 2024 02:41
A toast for shopify polaris component.
import { Banner } from "@shopify/polaris";
import { useEffect, useState } from "react";
export interface ToastProps {
id: string;
type?: "success" | "info" | "warning" | "critical";
title: string;
message: string;
timeout?: number;
}
/**
*
* @param {*} array : the array of objects to be distincted
* @returns Returns unique
*/
const distinct = (array) => {
const result = [];
const map = new Map();
for (const item of array) {
//Animations
function animateFrom(elem, direction) {
direction = direction || 1;
var x = 0,
y = direction * 100;
if (elem.classList.contains("gs_reveal_fromLeft")) {
x = -100;
y = 0;
} else if (elem.classList.contains("gs_reveal_fromRight")) {
x = 100;
@sonangrai
sonangrai / axiosInstance.js
Created September 21, 2021 06:16
THe axios instance which will interfere to get refresh token.
import axios from "axios";
import { refreshTokenApi } from "../api/auth";
import { loadUser } from "../Redux/reducers/authReducers";
import store from "../Redux/store";
export const axiosInstance = () => {
const baseURL = process.env.REACT_APP_BASE_API_URI;
let headers = {};
@sonangrai
sonangrai / sortArrayObject.js
Created July 21, 2021 13:53
Sort the array object as per the object property.
let arrays = [{name: "Sonang", sno: 32},{name: "Anjit", sno: 10}, {name: "Sujan", sno: 40}];
function compare( a, b ) {
if ( a.sno < b.sno ){
return -1;
}
if ( a.sno > b.sno ){
return 1;
}
return 0;
}
@sonangrai
sonangrai / DetectAdBlock.js
Created May 19, 2021 06:13
Component that detects the ad blocker in react app
import React, { useState, useEffect } from "react";
const DetectAdBlock = () => {
const [usingAdblock, setUsingAdblock] = useState(false);
let fakeAdBanner;
useEffect(() => {
if (fakeAdBanner) {
setUsingAdblock(() => {
if (fakeAdBanner.offsetHeight === 0) {
@sonangrai
sonangrai / double click event.txt
Created May 31, 2020 03:15
A double click event js. Click twice to change the font size. It implements the cookie form js.
var click1 = 0;
function font_size1(){
click1 += 1;
var sendthis;
if(click1 % 2 == 0){
document.getElementById("top_wrap").style.fontSize = "60%";
sendthis = "60%";
}else{
document.getElementById("top_wrap").style.fontSize = "80%";
sendthis = "80%";
@sonangrai
sonangrai / stopwatch.js
Last active April 5, 2020 04:02
A stopwatch js code
var sw = {
/* [INIT] */
etime : null, // holds HTML time display
erst : null, // holds HTML reset button
ego : null, // holds HTML start/stop button
timer : null, // timer object
now : 0, // current timer
init : function () {
// Get HTML elements
sw.etime = document.getElementById("sw-time");
// Cache selectors
var lastId,
topMenu = $("#menu-menu2"),
topMenuHeight = topMenu.outerHeight()+15,
// All list items
menuItems = topMenu.find("a"),
// Anchors corresponding to menu items
scrollItems = menuItems.map(function(){
var item = $($(this).attr("href"));
if (item.length) { return item; }