Skip to content

Commit

Permalink
feat: add did you know toasts
Browse files Browse the repository at this point in the history
  • Loading branch information
KostyaCholak committed Jul 20, 2024
1 parent 57ed514 commit 14eb69c
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"react-dom": "^18.2.0",
"react-highlight": "^0.15.0",
"react-konva": "^18.2.10",
"sonner": "^1.5.0",
"tailwind-merge": "^2.3.0",
"tailwindcss-animate": "^1.0.7",
"vaul": "^0.9.1",
Expand Down
10 changes: 10 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useEffect, useState } from "react";
import ExplainableView from "./ExplainableView";
import { ThemeProvider } from "./components/theme-provider";
import { Button } from "./components/ui/button";
import { toast } from "sonner"
import { useViewStore } from './storages/viewStorage';
import { useWebsocketURIStore } from './storages/websocketURIStore';

Expand All @@ -17,6 +18,13 @@ import { Representation } from "./sources";
import { pushHistory } from "./structures/history";
import ServerIsOutdatedComponent from "./components/ServerIsOutdatedComponent";


const didYouKnowMessages = [
"Did you know that you can Alt+Click a widget to reset its position",
"Did you know that you can Shft+Drag to move around without dragging widgets"
]


function checkVersionMatches(a: string, b: string) {
/* only major and minor versions are checked */

Expand Down Expand Up @@ -139,6 +147,8 @@ export default function App() {
]);

useEffect(() => {
toast(didYouKnowMessages[Math.floor(Math.random() * didYouKnowMessages.length)]);

api.onConnected(() => {
setIsConnected(true);
});
Expand Down
29 changes: 29 additions & 0 deletions src/components/ui/sonner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useTheme } from "next-themes"

Check failure on line 1 in src/components/ui/sonner.tsx

View workflow job for this annotation

GitHub Actions / build

Cannot find module 'next-themes' or its corresponding type declarations.
import { Toaster as Sonner } from "sonner"

type ToasterProps = React.ComponentProps<typeof Sonner>

const Toaster = ({ ...props }: ToasterProps) => {
const { theme = "system" } = useTheme()

return (
<Sonner
theme={theme as ToasterProps["theme"]}
className="toaster group"
toastOptions={{
classNames: {
toast:
"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",
description: "group-[.toast]:text-muted-foreground",
actionButton:
"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",
cancelButton:
"group-[.toast]:bg-muted group-[.toast]:text-muted-foreground",
},
}}
{...props}
/>
)
}

export { Toaster }
2 changes: 2 additions & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import App from './App.tsx'
import './index.css'
import { CookiesProvider } from 'react-cookie'
import { enableMapSet } from 'immer'
import { Toaster } from "@/components/ui/sonner"


enableMapSet()

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<CookiesProvider defaultSetOptions={{ path: '/', expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365) }}>
<Toaster />
<App />
</CookiesProvider>
</React.StrictMode>,
Expand Down
10 changes: 5 additions & 5 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import path from 'path'
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
import path from 'path';
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';

export default defineConfig({
plugins: [react()],
plugins: [react(), ],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
})
});

0 comments on commit 14eb69c

Please sign in to comment.