├── .eslintrc.json ├── .github └── FUNDING.yml ├── .gitignore ├── .tool-versions ├── LICENSE.md ├── README.md ├── next.config.js ├── package.json ├── postcss.config.js ├── public ├── favicon.svg └── screenshot.png ├── src ├── components │ ├── AuthButton.tsx │ ├── BlockActions.tsx │ ├── BlockConnnections.tsx │ ├── BlockContainer.tsx │ ├── BlockDndWrapper.tsx │ ├── BlockDragOverlay.tsx │ ├── BlockInfo.tsx │ ├── BlockViewer.tsx │ ├── BlocksGrid.tsx │ ├── BlocksGridItem.tsx │ ├── BlocksList.tsx │ ├── BlocksListItem.tsx │ ├── ChannelCreator.tsx │ ├── ChannelLoader.tsx │ ├── ChannelsIndexMenu.tsx │ ├── Desktop.tsx │ ├── Dialog.tsx │ ├── Header.tsx │ ├── Info.tsx │ ├── SaveLoadLayoutMenu.tsx │ ├── Spinner.tsx │ ├── UserMenu.tsx │ ├── Welcome.tsx │ ├── Window.tsx │ ├── WindowFooter.tsx │ ├── WindowScroller.tsx │ ├── WindowToolbar.tsx │ └── ZeroState.tsx ├── context │ ├── BlockContext.ts │ ├── BlockViewerContext.tsx │ ├── DesktopContext.tsx │ ├── DialogContext.tsx │ └── WindowContext.ts ├── hooks │ └── useArena.ts ├── icons │ ├── amux.svg │ ├── arena-mark.svg │ ├── github.svg │ ├── save.svg │ └── square.svg ├── lib │ ├── getErrorMessage.ts │ └── mosaic.ts ├── pages │ ├── _app.tsx │ ├── api │ │ └── auth │ │ │ └── [...nextauth].ts │ └── index.tsx ├── reducers │ ├── blocksReducer.ts │ └── channelsReducer.ts ├── styles │ └── globals.css └── types │ ├── index.d.ts │ └── nextauth.d.ts ├── tailwind.config.js ├── tsconfig.json ├── vercel.json └── yarn.lock /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "plugin:@typescript-eslint/recommended", 4 | // "plugin:@typescript-eslint/recommended-requiring-type-checking", 5 | "next/core-web-vitals", 6 | "plugin:tailwindcss/recommended", 7 | "standard" 8 | ], 9 | "parser": "@typescript-eslint/parser", 10 | "parserOptions": { 11 | "project": "./tsconfig.json", 12 | "tsconfigRootDir": "./" 13 | }, 14 | "plugins": [ 15 | "@typescript-eslint" 16 | ], 17 | "rules": { 18 | "@next/next/no-img-element": "off", 19 | "@typescript-eslint/indent": "off" 20 | } 21 | } -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [mguidetti] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | next-env.d.ts 15 | 16 | # production 17 | /build 18 | 19 | # misc 20 | .DS_Store 21 | *.pem 22 | 23 | # debug 24 | npm-debug.log* 25 | yarn-debug.log* 26 | yarn-error.log* 27 | .pnpm-debug.log* 28 | 29 | # local env files 30 | .env*.local 31 | 32 | # vercel 33 | .vercel 34 | -------------------------------------------------------------------------------- /.tool-versions: -------------------------------------------------------------------------------- 1 | nodejs 23.3.0 -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Michael Guidetti 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Are.na Multiplexer logo 2 | 3 | # Are.na Multiplexer 4 | 5 | Are.na Multiplexer is a tiling window manager for [Are.na](https://are.na) 6 | 7 | Hosted at https://arena-mux.michaelguidetti.info 8 | 9 | Screenshot of Are.na Multiplexer 10 | 11 | ## Development 12 | 13 | ### Setup 14 | - Fork and clone this repo 15 | - Register an application with Are.na at https://dev.are.na/oauth/applications 16 | - Add `https://localhost:3001/api/auth/callback/arena` as a callback URL in your registered application's settings 17 | - Set the following variables in `.env.local` 18 | | KEY | VALUE | 19 | | --- | --- | 20 | | `ARENA_APP_ID` | `UID` from your registered app at dev.are.na | 21 | | `ARENA_APP_SECRET` | `Secret` from your registered app at dev.are.na | 22 | | `NEXT_AUTH_SECRET` | Generate local secret by running `openssl rand -base64 32` | 23 | | `NEXT_AUTH_URL` | `https://localhost:3001` | 24 | - Run `yarn install` 25 | - Run `yarn dev` 26 | - Visit https://localhost:3001 (bypass unsigned certificate warning) 27 | -------------------------------------------------------------------------------- /next.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | 3 | const nextConfig = { 4 | reactStrictMode: true, 5 | env: { 6 | npm_package_version: process.env.npm_package_version 7 | }, 8 | webpack: config => { 9 | config.module.rules.push({ 10 | test: /\.svg$/i, 11 | issuer: /\.[jt]sx?$/, 12 | use: ['@svgr/webpack'] 13 | }) 14 | 15 | return config 16 | } 17 | } 18 | 19 | module.exports = nextConfig 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "arena-multiplexer", 3 | "version": "0.2.0", 4 | "private": true, 5 | "license": "MIT", 6 | "repository": "https://github.com/mguidetti/arena-multiplexer", 7 | "author": "Michael Guidetti ", 8 | "scripts": { 9 | "dev": "next dev & local-ssl-proxy --source 3001 --target 3000", 10 | "build": "next build", 11 | "start": "next start", 12 | "lint": "next lint" 13 | }, 14 | "dependencies": { 15 | "@dnd-kit/core": "^6.0.7", 16 | "@heroicons/react": "^2.0.16", 17 | "@radix-ui/react-alert-dialog": "^1.0.2", 18 | "@radix-ui/react-dialog": "^1.0.3", 19 | "@radix-ui/react-popover": "1.0.3", 20 | "@vercel/analytics": "^0.1.8", 21 | "arena-ts": "^0.1.4", 22 | "dayjs": "^1.11.7", 23 | "debounce-promise": "^3.1.2", 24 | "next": "14.2.21", 25 | "next-auth": "^4.24.5", 26 | "react": "18.2.0", 27 | "react-device-detect": "^2.2.2", 28 | "react-dom": "18.2.0", 29 | "react-hotkeys-hook": "^4.3.4", 30 | "react-mosaic-component": "^5.3.0", 31 | "react-select": "^5.7.0", 32 | "react-virtuoso": "^4.1.0", 33 | "uuid": "^9.0.0" 34 | }, 35 | "devDependencies": { 36 | "@svgr/webpack": "^6.5.1", 37 | "@tailwindcss/typography": "^0.5.9", 38 | "@types/debounce-promise": "^3.1.6", 39 | "@types/node": "^18.14.1", 40 | "@types/react": "^18.0.28", 41 | "@types/uuid": "^9.0.1", 42 | "@typescript-eslint/eslint-plugin": "^5.53.0", 43 | "@typescript-eslint/parser": "^5.53.0", 44 | "autoprefixer": "^10.4.13", 45 | "eslint": "8.33.0", 46 | "eslint-config-next": "13.1.6", 47 | "eslint-config-standard": "^17.0.0", 48 | "eslint-import-resolver-typescript": "^3.5.3", 49 | "eslint-plugin-import": "^2.27.5", 50 | "eslint-plugin-n": "^15.6.1", 51 | "eslint-plugin-promise": "^6.1.1", 52 | "eslint-plugin-tailwindcss": "^3.9.0", 53 | "local-ssl-proxy": "^2.0.5", 54 | "postcss": "^8.4.31", 55 | "tailwind-scrollbar": "^2.1.0", 56 | "tailwindcss": "^3.2.4", 57 | "typescript": "^4.9.5" 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {} 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /public/favicon.svg: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /public/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mguidetti/are.na-multiplexer/5fe600319d6d720350cdd1846445331c58b1c6d3/public/screenshot.png -------------------------------------------------------------------------------- /src/components/AuthButton.tsx: -------------------------------------------------------------------------------- 1 | import { useSession, signIn } from 'next-auth/react' 2 | import ArenaMark from '@/icons/arena-mark.svg' 3 | import Spinner from './Spinner' 4 | 5 | export default function AuthButton () { 6 | const session = useSession() 7 | const { status } = session 8 | const loading = status === 'loading' 9 | 10 | if (loading) { 11 | return ( 12 |
13 | 14 |
Loading
15 |
16 | ) 17 | } else { 18 | return ( 19 |
20 | 27 |
28 | ) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/components/BlockActions.tsx: -------------------------------------------------------------------------------- 1 | import { useBlockContext } from '@/context/BlockContext' 2 | import { useWindowContext } from '@/context/WindowContext' 3 | import { EyeIcon, LinkIcon, TrashIcon } from '@heroicons/react/20/solid' 4 | 5 | function BlockActions () { 6 | const { data, handleView, handleDelete } = useBlockContext() 7 | const windowCtx = useWindowContext() 8 | 9 | return ( 10 | <> 11 | {data.class === 'Link' && ( 12 | 19 | 20 | 21 | )} 22 | 25 | {windowCtx.canDelete && ( 26 | 29 | )} 30 | 31 | ) 32 | } 33 | 34 | export default BlockActions 35 | -------------------------------------------------------------------------------- /src/components/BlockConnnections.tsx: -------------------------------------------------------------------------------- 1 | import { useBlockViewerActionsContext } from '@/context/BlockViewerContext' 2 | import { useDesktopActionsContext } from '@/context/DesktopContext' 3 | import { useArena } from '@/hooks/useArena' 4 | import { ArenaBlock, ArenaChannelWithDetails, ConnectionData } from 'arena-ts' 5 | import classNames from 'classnames' 6 | import { useCallback, useEffect, useState } from 'react' 7 | import Spinner from './Spinner' 8 | 9 | function BlockConnections ({ blockData }: {blockData: ArenaBlock & ConnectionData}) { 10 | const [connections, setConnections] = useState([]) 11 | const arena = useArena() 12 | const { addChannelWindow } = useDesktopActionsContext() 13 | const setBlockViewerData = useBlockViewerActionsContext() 14 | 15 | const fetchChannels = useCallback(async () => { 16 | if (!arena) return 17 | 18 | const results = await arena.block(blockData.id).channels() 19 | 20 | setConnections(results.channels) 21 | }, [arena, blockData]) 22 | 23 | useEffect(() => { 24 | fetchChannels() 25 | }, [fetchChannels]) 26 | 27 | const handleChannelClick = (channel: ArenaChannelWithDetails) => { 28 | addChannelWindow(channel) 29 | setBlockViewerData(null) 30 | } 31 | 32 | if (connections.length) { 33 | return ( 34 | 51 | ) 52 | } else { 53 | return
Loading connections
54 | } 55 | } 56 | 57 | export default BlockConnections 58 | -------------------------------------------------------------------------------- /src/components/BlockContainer.tsx: -------------------------------------------------------------------------------- 1 | import { BlockContext, BlockContextType } from '@/context/BlockContext' 2 | import { useBlockViewerActionsContext } from '@/context/BlockViewerContext' 3 | import { useDesktopActionsContext } from '@/context/DesktopContext' 4 | import { useDialogActionsContext } from '@/context/DialogContext' 5 | import { useWindowContext } from '@/context/WindowContext' 6 | import { UniqueIdentifier, useDraggable } from '@dnd-kit/core' 7 | import { ArenaChannelContents } from 'arena-ts' 8 | import classNames from 'classnames' 9 | import { ReactNode, useCallback, useMemo, useState } from 'react' 10 | import { ChannelWindowState } from './Desktop' 11 | 12 | export interface DraggingBlockData { 13 | type: 'block', 14 | block: ArenaChannelContents, 15 | window: { 16 | id: number, 17 | view: ChannelWindowState['view'], 18 | scale: ChannelWindowState['scale'] 19 | } 20 | } 21 | 22 | interface BlockContainerProps { 23 | data: ArenaChannelContents, 24 | children: ReactNode 25 | } 26 | 27 | function BlockContainer ({ data, children }: BlockContainerProps) { 28 | const { addChannelWindow } = useDesktopActionsContext() 29 | const { channel, view, scale, disconnectBlock } = useWindowContext() 30 | const setBlockViewerData = useBlockViewerActionsContext() 31 | const setDialog = useDialogActionsContext() 32 | const [isHovering, setIsHovering] = useState(false) 33 | const isPending = useMemo(() => data.connection_id === undefined, [data]) 34 | 35 | const { attributes, listeners, setNodeRef, isDragging } = useDraggable({ 36 | id: data.connection_id as UniqueIdentifier, 37 | data: { 38 | type: 'block', 39 | block: { ...data }, 40 | window: { 41 | id: channel.id, 42 | view, 43 | scale 44 | } 45 | } 46 | }) 47 | 48 | const handleView = useCallback(() => { 49 | if (data.class === 'Channel') { 50 | addChannelWindow(data) 51 | } else { 52 | setBlockViewerData(data) 53 | } 54 | }, [data, addChannelWindow, setBlockViewerData]) 55 | 56 | const handleDelete = useCallback(() => { 57 | setDialog({ 58 | isOpen: true, 59 | title: 'Are you sure you want to disconnect this block?', 60 | message: 'This cannot be undone', 61 | onConfirm: () => disconnectBlock(data) 62 | }) 63 | }, [data, setDialog, disconnectBlock]) 64 | 65 | const handleHover = () => { 66 | setIsHovering(prevState => !prevState) 67 | } 68 | 69 | const contextValues = useMemo( 70 | () => ({ 71 | data, 72 | handleDelete, 73 | handleView, 74 | isPending, 75 | isDragging, 76 | isHovering 77 | }), 78 | [data, handleDelete, handleView, isPending, isDragging, isHovering] 79 | ) 80 | 81 | return ( 82 |
94 | {children} 95 |
96 | ) 97 | } 98 | 99 | export default BlockContainer 100 | -------------------------------------------------------------------------------- /src/components/BlockDndWrapper.tsx: -------------------------------------------------------------------------------- 1 | import { 2 | CollisionDetection, 3 | DndContext, 4 | DragOverlay, 5 | DragStartEvent, 6 | PointerSensor, 7 | pointerWithin, 8 | rectIntersection, 9 | useSensor, 10 | useSensors 11 | } from '@dnd-kit/core' 12 | import { ArenaChannelContents } from 'arena-ts' 13 | import { ReactNode, useState } from 'react' 14 | import BlockDragOverlay from './BlockDragOverlay' 15 | import { ChannelWindowState } from './Desktop' 16 | 17 | interface DraggingBlockState { 18 | block: ArenaChannelContents, 19 | window: ChannelWindowState 20 | } 21 | 22 | function BlockDndWrapper ({ children }: { children: ReactNode }) { 23 | const [draggingBlock, setDraggingBlock] = useState() 24 | 25 | const pointerSensor = useSensor(PointerSensor, { 26 | activationConstraint: { 27 | distance: 5 28 | } 29 | }) 30 | 31 | const sensors = useSensors(pointerSensor) 32 | 33 | const collisionDetection: CollisionDetection = (args) => { 34 | const pointerCollisions = pointerWithin(args) 35 | 36 | if (pointerCollisions.length > 0) { 37 | return pointerCollisions 38 | } 39 | 40 | return rectIntersection(args) 41 | } 42 | 43 | const handleDragStart = (event: DragStartEvent) => { 44 | const current = event.active.data.current 45 | 46 | setDraggingBlock({ 47 | block: current?.block, 48 | window: current?.window 49 | }) 50 | } 51 | 52 | const clearDraggingBlock = () => { 53 | setDraggingBlock(null) 54 | } 55 | 56 | return ( 57 | 64 | {children} 65 | 66 | {draggingBlock && ( 67 | 68 | )} 69 | 70 | 71 | ) 72 | } 73 | 74 | export default BlockDndWrapper 75 | -------------------------------------------------------------------------------- /src/components/BlockDragOverlay.tsx: -------------------------------------------------------------------------------- 1 | import { ArenaChannelContents } from 'arena-ts' 2 | import { CSSProperties } from 'react' 3 | import BlocksGridItem from './BlocksGridItem' 4 | import BlocksListItem from './BlocksListItem' 5 | import { ChannelWindowState } from './Desktop' 6 | 7 | function BlockDragOverlay ({ data, window }: {data: ArenaChannelContents, window: ChannelWindowState }) { 8 | const renderItem = () => { 9 | switch (window.view) { 10 | case 'grid': 11 | return 12 | case 'list': 13 | return 14 | } 15 | } 16 | 17 | return ( 18 |
19 | {renderItem()} 20 |
21 |
22 | ) 23 | } 24 | 25 | export default BlockDragOverlay 26 | -------------------------------------------------------------------------------- /src/components/BlockInfo.tsx: -------------------------------------------------------------------------------- 1 | import { ArrowTopRightOnSquareIcon, ChevronRightIcon } from '@heroicons/react/24/solid' 2 | import { ArenaBlock, ConnectionData } from 'arena-ts' 3 | import dayjs from 'dayjs' 4 | import relativeTime from 'dayjs/plugin/relativeTime' 5 | import { Dispatch, SetStateAction } from 'react' 6 | import BlockConnections from './BlockConnnections' 7 | 8 | dayjs.extend(relativeTime) 9 | 10 | interface BlockInfoProps { 11 | blockData: ArenaBlock & ConnectionData, 12 | setInfoVisible: Dispatch> 13 | } 14 | 15 | function BlockInfo ({ blockData, setInfoVisible }: BlockInfoProps) { 16 | return ( 17 |
18 | 21 | 22 |
23 |

{blockData.generated_title}

24 |
25 | {blockData.description &&

{blockData.description}

} 26 |

27 | Created {dayjs(blockData.created_at).fromNow()} by{' '} 28 | 29 | {blockData.user.username} 30 | 31 |

32 | {blockData.source && ( 33 | 34 | Source:{' '} 35 | 36 | {blockData.source.title} 37 | 38 | 39 | )} 40 |
41 |
42 | 43 |
44 | 45 |

Connections

46 | 47 |
48 | 49 |
50 |
51 | ) 52 | } 53 | 54 | export default BlockInfo 55 | -------------------------------------------------------------------------------- /src/components/BlockViewer.tsx: -------------------------------------------------------------------------------- 1 | import { useBlockViewerActionsContext, useBlockViewerContext } from '@/context/BlockViewerContext' 2 | import ArenaMarkIcon from '@/icons/arena-mark.svg' 3 | import { InformationCircleIcon, XMarkIcon } from '@heroicons/react/24/solid' 4 | import * as Dialog from '@radix-ui/react-dialog' 5 | import { ArenaBlock } from 'arena-ts' 6 | import { useState } from 'react' 7 | import { useHotkeys } from 'react-hotkeys-hook' 8 | import BlockInfo from './BlockInfo' 9 | import Spinner from './Spinner' 10 | 11 | function AttachmentBlock ({ data }: { data: ArenaBlock }) { 12 | const renderBody = () => { 13 | if (data.image) { 14 | return 15 | } else { 16 | return {data.generated_title} 17 | } 18 | } 19 | 20 | return ( 21 | 22 | {renderBody()} 23 | 24 | ) 25 | } 26 | 27 | function ImageBlock ({ data }: { data: ArenaBlock }) { 28 | const [imageLoaded, setImageLoaded] = useState(false) 29 | 30 | const handleImageLoaded = () => { 31 | setImageLoaded(true) 32 | } 33 | 34 | return ( 35 | <> 36 | {!imageLoaded && ( 37 |
38 | 39 |
40 | )} 41 | 42 | 48 | 55 | 56 | ) 57 | } 58 | 59 | function LinkBlock ({ data }: { data: ArenaBlock }) { 60 | return ( 61 | 62 |
{data.source?.url}
63 | 64 |
65 | ) 66 | } 67 | 68 | function MediaBlock ({ data }: { data: ArenaBlock }) { 69 | const embed = { __html: data.embed?.html || '' } 70 | 71 | return ( 72 |
73 | ) 74 | } 75 | 76 | function TextBlock ({ data }: { data: ArenaBlock }) { 77 | const body = { __html: data.content_html || '' } 78 | 79 | return ( 80 |
84 | ) 85 | } 86 | 87 | function BlockViewer () { 88 | const setBlockViewerData = useBlockViewerActionsContext() 89 | const blockData = useBlockViewerContext() 90 | const [infoVisible, setInfoVisible] = useState(true) 91 | 92 | useHotkeys('i', () => setInfoVisible(prevState => !prevState), { enabled: blockData !== null }) 93 | 94 | if (!blockData) { 95 | return null 96 | } 97 | 98 | const renderBlock = () => { 99 | switch (blockData.class) { 100 | case 'Attachment': 101 | return 102 | case 'Image': 103 | return 104 | case 'Media': 105 | return 106 | case 'Link': 107 | return 108 | case 'Text': 109 | return 110 | } 111 | } 112 | 113 | return ( 114 | !open && setBlockViewerData(null)}> 115 | 116 | 117 | 118 |
119 | {renderBlock()} 120 |
121 | 122 | 125 | 126 | 127 | 130 | 131 | 132 | 139 | 140 | 141 | 142 | {!infoVisible && ( 143 | 146 | )} 147 |
148 |
149 |
150 | ) 151 | } 152 | 153 | export default BlockViewer 154 | -------------------------------------------------------------------------------- /src/components/BlocksGrid.tsx: -------------------------------------------------------------------------------- 1 | import { useWindowContext } from '@/context/WindowContext' 2 | import { ArenaChannelContents } from 'arena-ts' 3 | import React from 'react' 4 | import { Components, VirtuosoGrid } from 'react-virtuoso' 5 | import BlockContainer from './BlockContainer' 6 | import BlocksGridItem from './BlocksGridItem' 7 | import WindowFooter from './WindowFooter' 8 | import WindowScroller from './WindowScroller' 9 | 10 | const ListContainer: Components['List'] = React.forwardRef(function ListContainer (props, ref) { 11 | return ( 12 |
13 |
14 |
15 | ) 16 | }) 17 | 18 | function BlocksGrid ({ blocks }: { blocks: ArenaChannelContents[] }) { 19 | const { loadMore } = useWindowContext() 20 | 21 | return ( 22 | ( 32 | 33 | 34 | 35 | )} 36 | /> 37 | ) 38 | } 39 | 40 | export default React.memo(BlocksGrid) 41 | -------------------------------------------------------------------------------- /src/components/BlocksGridItem.tsx: -------------------------------------------------------------------------------- 1 | import { useBlockContext } from '@/context/BlockContext' 2 | import { ArenaBlock, ArenaChannelContents, ArenaChannelWithDetails } from 'arena-ts' 3 | import classNames from 'classnames' 4 | import BlockActions from './BlockActions' 5 | import Spinner from './Spinner' 6 | 7 | function BlocksGridItem ({ data }: {data: ArenaChannelContents}) { 8 | const { isPending, isDragging, isHovering } = useBlockContext() 9 | 10 | const renderBlock = () => { 11 | switch (data.class) { 12 | case 'Attachment': 13 | return 14 | case 'Channel': 15 | return 16 | case 'Image': 17 | return 18 | case 'Media': 19 | return 20 | case 'Link': 21 | return 22 | case 'Text': 23 | return 24 | } 25 | } 26 | 27 | return ( 28 |
29 | {renderBlock()} 30 | 31 | {(isHovering || isDragging) && ( 32 |
33 | {isHovering && ( 34 |
35 | 36 |
37 | )} 38 |
39 | )} 40 | 41 | {isPending && ( 42 |
43 | 44 |
45 | )} 46 |
47 | ) 48 | } 49 | 50 | function AttachmentBlock ({ data }: {data: ArenaBlock}) { 51 | if (data.image) { 52 | return 53 | } else { 54 | return ( 55 |
56 |

{data.generated_title}

57 |
58 | ) 59 | } 60 | } 61 | 62 | function ChannelBlock ({ data }: {data: ArenaChannelWithDetails}) { 63 | return ( 64 |
71 | 72 | {data.title} 73 | 74 | 75 | by {data.user?.username} 76 |
77 | {data.length} blocks 78 |
79 |
80 | ) 81 | } 82 | 83 | function ImageBlock ({ data }: {data: ArenaBlock}) { 84 | return ( 85 | 86 | ) 87 | } 88 | 89 | function TextBlock ({ data }: {data: ArenaBlock}) { 90 | const body = { __html: data.content_html || '' } 91 | 92 | return ( 93 |
94 |
98 |
99 | ) 100 | } 101 | 102 | export default BlocksGridItem 103 | -------------------------------------------------------------------------------- /src/components/BlocksList.tsx: -------------------------------------------------------------------------------- 1 | import { useWindowContext } from '@/context/WindowContext' 2 | import { ArenaChannelContents } from 'arena-ts' 3 | import React from 'react' 4 | import { Components, Virtuoso } from 'react-virtuoso' 5 | import BlockContainer from './BlockContainer' 6 | import BlocksListItem from './BlocksListItem' 7 | import WindowFooter from './WindowFooter' 8 | import WindowScroller from './WindowScroller' 9 | 10 | const ListContainer: Components['List'] = React.forwardRef(function ListContainer (props, ref) { 11 | return
12 | }) 13 | 14 | function BlocksList ({ blocks }: {blocks: ArenaChannelContents[]}) { 15 | const windowCtx = useWindowContext() 16 | 17 | return ( 18 | ( 28 | 29 | 30 | 31 | )} 32 | /> 33 | ) 34 | } 35 | 36 | export default React.memo(BlocksList) 37 | -------------------------------------------------------------------------------- /src/components/BlocksListItem.tsx: -------------------------------------------------------------------------------- 1 | import { useBlockContext } from '@/context/BlockContext' 2 | import SquareIcon from '@/icons/square.svg' 3 | import { ArenaBlock, ArenaChannelContents, ArenaChannelWithDetails } from 'arena-ts' 4 | import classNames from 'classnames' 5 | import BlockActions from './BlockActions' 6 | import Spinner from './Spinner' 7 | 8 | function ChannelBody ({ data }: {data: ArenaChannelWithDetails}) { 9 | return ( 10 |
17 |
18 | 19 |
20 |
{`${data.user?.username} / ${data.title}`}
21 |
22 | ) 23 | } 24 | 25 | function BlockBody ({ data }: {data:ArenaBlock}) { 26 | return ( 27 | <> 28 |
29 | {data.image && } 30 |
31 |
{data.title || data.generated_title}
32 | 33 | ) 34 | } 35 | 36 | function BlocksListItem ({ data }: {data: ArenaChannelContents}) { 37 | const { isPending, isHovering } = useBlockContext() 38 | 39 | return ( 40 |
43 | {data.class === 'Channel' ? : } 44 | 45 | {isPending && ( 46 |
47 | 48 |
49 | )} 50 | 51 | {isHovering && ( 52 |
53 | 54 |
55 | )} 56 |
57 | ) 58 | } 59 | 60 | export default BlocksListItem 61 | -------------------------------------------------------------------------------- /src/components/ChannelCreator.tsx: -------------------------------------------------------------------------------- 1 | import { useArena } from '@/hooks/useArena' 2 | import getErrorMessage from '@/lib/getErrorMessage' 3 | import { PlusIcon } from '@heroicons/react/24/solid' 4 | import * as Popover from '@radix-ui/react-popover' 5 | import { ArenaChannelWithDetails, ChannelStatus } from 'arena-ts' 6 | import classNames from 'classnames' 7 | import { ChangeEvent, FormEvent, useState } from 'react' 8 | import { useDesktopActionsContext } from '../context/DesktopContext' 9 | import Spinner from './Spinner' 10 | 11 | interface FormDataType { 12 | name: '', 13 | privacy: ChannelStatus | '' 14 | } 15 | 16 | function ChannelCreator () { 17 | const { addChannelWindow } = useDesktopActionsContext() 18 | const arena = useArena() 19 | 20 | const [open, setOpen] = useState(false) 21 | const [isCreating, setIsCreating] = useState(false) 22 | const [formData, setFormData] = useState({ 23 | name: '', 24 | privacy: '' 25 | }) 26 | const [error, setError] = useState(null) 27 | 28 | const handleChange = (event: ChangeEvent) => { 29 | setFormData({ ...formData, [event.target.name]: event.target.value }) 30 | } 31 | 32 | const createChannel = async (event: FormEvent) => { 33 | event.preventDefault() 34 | 35 | if (!arena || formData.name === '' || formData.privacy === '') return 36 | 37 | setIsCreating(true) 38 | 39 | try { 40 | const results = await arena 41 | .channel(formData.name) 42 | .create(formData.privacy) 43 | 44 | if (results) { 45 | addChannelWindow(results as ArenaChannelWithDetails) 46 | setFormData({ name: '', privacy: '' }) 47 | setOpen(false) 48 | } 49 | } catch (error) { 50 | console.warn(error) 51 | setError(getErrorMessage(error)) 52 | } finally { 53 | setIsCreating(false) 54 | } 55 | } 56 | 57 | return ( 58 | 59 | 60 | 65 | 66 | 71 | {isCreating && ( 72 |
73 | 74 |
75 | )} 76 | 77 | {error &&

{error}

} 78 | 79 |
83 |

Create New Channel

84 | 85 | 93 | 94 | 110 | 111 | 114 |
115 | 116 |
117 |
118 | ) 119 | } 120 | 121 | export default ChannelCreator 122 | -------------------------------------------------------------------------------- /src/components/ChannelLoader.tsx: -------------------------------------------------------------------------------- 1 | import { ArenaChannelWithDetails } from 'arena-ts' 2 | import classNames from 'classnames' 3 | import debounce from 'debounce-promise' 4 | import { useRef } from 'react' 5 | import { useHotkeys } from 'react-hotkeys-hook' 6 | import { SelectInstance, SingleValue } from 'react-select' 7 | import AsyncSelect from 'react-select/async' 8 | import { useDesktopActionsContext } from '../context/DesktopContext' 9 | import { useArena } from '../hooks/useArena' 10 | 11 | type Option = ArenaChannelWithDetails 12 | 13 | function ChannelLoader () { 14 | const { addChannelWindow } = useDesktopActionsContext() 15 | const arena = useArena() 16 | const select = useRef>(null) 17 | 18 | useHotkeys('/', () => select.current?.focus(), { 19 | ignoreModifiers: true, 20 | preventDefault: true 21 | }) 22 | 23 | const loadOptions = debounce(async (inputValue: string) => { 24 | if (!inputValue || !arena) return [] 25 | 26 | const results = await arena.search.channels(inputValue, { page: 1, per: 20 }) 27 | return results.channels as ArenaChannelWithDetails[] // HACK: Type correction 28 | }, 200) 29 | 30 | const handleSelectChange = (channel: SingleValue