Skip to content

Instantly share code, notes, and snippets.

View colinfwren's full-sized avatar

Colin Wren colinfwren

View GitHub Profile
@colinfwren
colinfwren / createWidgets.py
Created December 17, 2021 16:53
Create Widgets via Miro REST API
import requests
BOARD_ID = ''
AUTH_TOKEN = ''
URL = 'https://api.miro.com/v1/boards/{board_id}/widgets'.format(board_id=BOARD_ID)
FRAME_ID = ''
headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
@colinfwren
colinfwren / readAndUpdateWidgets.js
Created December 17, 2021 16:35
Read and Update Miro Board Widgets
async function updateWidgets(widgetIds) {
const widgetObjects = await Promise.all(widgetsIds.map(async (widgetId) => {
const widgets = await miro.board.widgets.get({ id: widgetId })
if (widgets.length > 0) {
return widgets[0]
}
return null
}))
const widgets = widgetObjects.filter(x => x !== null)
widgets.forEach((widget) => {
@colinfwren
colinfwren / miroEventListener.jsx
Last active December 17, 2021 16:16
Listening for Miro events
import React, { useEffect, useState } from 'react'
function App() {
const [selection, setSelection] = useState([])
const [isLoading, setIsLoading] = useState(true)
async function setInitialSelection() {
const selection = await miro.board.selection.get()
setSelection(selection)
@colinfwren
colinfwren / getSelectedConnections.js
Created October 6, 2021 00:24
Getting the selected connections based on the edges in a line
// Connections have this shape
// {
// key: "connection-1",
// x: 0,
// y: 0,
// commands: [
// {
// command: "M",
// x: 180,
// y: 280
@colinfwren
colinfwren / getSelectedRects.js
Created October 6, 2021 00:21
Getting the selected rectangles on the stage
// Steps have this shape
// export const steps = [
// {
// key: "step-1",
// x: 100,
// y: 100,
// width: 100,
// height: 200
// },
// ];
@colinfwren
colinfwren / MapWithSelectionPreview.jsx
Created October 6, 2021 00:18
Map showing selection preview
import React, { useContext, useState } from "react";
import { Rect, Stage, Layer } from "react-konva";
import AppContext, { AppConsumer, AppProvider } from "./AppContext";
import { MapContent } from "./MapContent";
export function Map() {
const { isInSelectMode } = useContext(AppContext);
const [selection, setSelection] = useState(null);
function handleMouseDown(e) {
@colinfwren
colinfwren / MapUsingIsInSelectMode.jsx
Last active October 6, 2021 00:15
Map component using isInSelectMode value
import React, { useContext } from "react";
import { Stage } from "react-konva";
import AppContext, { AppConsumer, AppProvider } from "./AppContext";
import { MapContent } from "./MapContent";
export function Map() {
const { isInSelectMode } = useContext(AppContext);
return (
<AppConsumer>
@colinfwren
colinfwren / index.js
Created October 6, 2021 00:11
Capturing key events at the top most level and passing into context for use in app
import React, { useEffect, useState } from "react";
import { AppProvider } from "./AppContext";
import { Map } from "./Map";
export default function App() {
const [isInSelectMode, setIsInSelectMode] = useState(false);
const [selectedEntities, setSelectedEntities] = useState([]);
function handleKeyDown(e) {
if (!isInSelectMode && e.keyCode === 16) {
@colinfwren
colinfwren / ViewboxContext.js
Created September 28, 2021 20:41
ViewBox Context
import { createContext } from 'react';
const ViewBoxContext = createContext({
xPos: 75,
setXPos: () => null,
yPos: 75,
setYPos: () => null,
scale: 1,
setScale: () => null,
scaleDelta: 0,
@colinfwren
colinfwren / renderingUnionTypes.js
Created September 22, 2021 22:35
Rending Union types
function TypeOne({ title, subtitle }) {
return (
<h1>{title}</h1>
<p>{subtitle}</p>
)
}
function TypeTwo({ image, content }) {
return (
<div>