Skip to content

Instantly share code, notes, and snippets.

View meetzaveri's full-sized avatar
🐞
Debugging

Meet Zaveri meetzaveri

🐞
Debugging
View GitHub Profile
@meetzaveri
meetzaveri / hasura_generate_apply_seeds_script_automation.md
Last active November 28, 2022 12:43
This markdown file explains how to first generate seeds and apply seeds via automation.
@meetzaveri
meetzaveri / resitified_endpoints_feature_request_draft.md
Last active September 9, 2022 13:04
Issue draft for GH feature request on allowing non-admin role users to access OpenAPI spec 3 RESTified endpoints API

Is your proposal related to a problem?

The OpenAPI 3 specification of the REST endpoints are exposed at /api/swagger/json for admin role only. We want that API to be exposed to different roles too. So different roles will be able to access different schemas (as per the permission level defined in hasura).

Let me explain this with an example: For eg., I have a book table and an author table. And I make a mutation to insert a book, and create a RESTified endpoint from it (as an admin).

I create a role named "editor". This editor role may have permissions to run the mutation to insert a book, but nothing else. But the admin role will be able to insert the book, and also the author through the relationship.

Attaching docs here for reference - https://hasura.io/docs/latest/api-reference/restified/#openapi-3-specification

@meetzaveri
meetzaveri / trackTabsOpenWrapper.js
Created March 13, 2022 10:38
Track tabs open for same website for react.js app
useEffect(() => {
// define increment counter part
const tabsOpen = localStorage.getItem('tabsOpen')
console.log('tabsOpen', tabsOpen)
if (tabsOpen == null) {
localStorage.setItem('tabsOpen', 1)
} else {
localStorage.setItem('tabsOpen', parseInt(tabsOpen) + parseInt(1))
}
@meetzaveri
meetzaveri / useLoadMoreOnScroll.md
Created July 26, 2021 12:53
load more on scroll hook
const { useRef, useEffect } = require('react')

const useLoadMoreOnScroll = (count, data, nextPage, fetch = () => null) => {
    const hasMore = count > data?.length
    const root = useRef()
    const isLoadingMore = useRef(false)

    useEffect(()=>{
@meetzaveri
meetzaveri / example_unmount_hook.js
Created November 28, 2020 11:53
Hook for listening for unmounting for component
import React, { useEffect } from 'react';
const ProfileContainer = () => {
// generally I prefer this as useEffect with empty args[]
useEffect(() => {
fetch('/api/user') // perform any side effects or network requests
// you can have return() for this function which will be executed once component will unmount
import React, { useEffect } from 'react';
import ProfilePage from './ProfilePage';
const ProfileContainer = () => {
useEffect(() => {
fetch('/api/user') // perform any side effects or network requests
}, []); // <-- empty array means 'run once'
return <ProfilePage />;
import React, { useEffect } from 'react';
const Container = () => {
const userInfo = props.userInfo;
const makeAPICall = () => {
// do your async actions, side effects or network effects
}
useEffect(makeAPICall,[userInfo])
return (<div>Example</div>);
@meetzaveri
meetzaveri / dayjs_scripts.md
Last active September 26, 2020 13:11
Utility scripts for dayjs. Shows how to get timestamp, date string and formatted data from dayjs library

To get timestamp

dayjs().valueOf()
// 1598941800000

// OR

dayjs(`${selectedTime.year}-${selectedTime.month}-${dateValue}`).valueOf()
// 1598941800000
@meetzaveri
meetzaveri / addHoursandMinsToTimestamp.md
Created August 18, 2020 03:04
Adds hours and minutes to timestamp

Code

 console.log('endValue', value) // 03:25
    const { currentTimeStamp } = this.state
    const generateTimeInMs = value + ':00'

    let dateTemplate = moment(currentTimeStamp).format('DD MMM YY')
 const newTimeStamp = Date.parse(dateTemplate + ' ' + generateTimeInMs)
@meetzaveri
meetzaveri / netlify_build_script.md
Created July 31, 2020 11:22
Build script to support netlify environment

In package.json

"build": "yarn build:css &amp;&amp; CI= react-scripts build",