-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from Nounspace/LayoutSystem
[CLIENT] Basic Fidget Setup + Layout System
- Loading branch information
Showing
34 changed files
with
1,041 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { loadPosthogAnalytics } from "@/common/lib/analytics"; | ||
import CommandPalette from "@/common/ui/components/CommandPalette"; | ||
import Home from "@/common/ui/templates/home"; | ||
import { rainbowKitTheme, config } from "@/common/ui/templates/rainboxkit"; | ||
import { RainbowKitProvider } from "@rainbow-me/rainbowkit"; | ||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
import { PostHogProvider } from "posthog-js/react"; | ||
import React, { Suspense } from "react" | ||
import { WagmiProvider } from "wagmi"; | ||
|
||
export const metadata = { | ||
title: 'Nounspace', | ||
description: 'Nounspace is a client for Farcaster', | ||
openGraph: { | ||
siteName: "Nounspace", | ||
title: "Nounspace", | ||
type: "website", | ||
description: "Nounspace is a client for Farcaster", | ||
images: { | ||
url: `${process.env.NEXT_PUBLIC_URL}/images/nounspace_og.png`, | ||
type: "image/png", | ||
width: 1200, | ||
height: 737, | ||
}, | ||
url: process.env.NEXT_PUBLIC_URL, | ||
}, | ||
icons: { | ||
icon: [ | ||
{ | ||
url: "/images/favicon.ico", | ||
}, | ||
{ | ||
url: "/images/favicon-32x32.png", | ||
sizes: "32x32", | ||
}, | ||
{ | ||
url: "/images/favicon-16x16.png", | ||
sizes: "16x16", | ||
}, | ||
], | ||
apple: "/images/apple-touch-icon.png", | ||
}, | ||
} | ||
|
||
const posthog = loadPosthogAnalytics(); | ||
|
||
const queryClient = new QueryClient(); | ||
|
||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
return ( | ||
<html lang="en"> | ||
<body> | ||
<Suspense> | ||
{ children } | ||
</Suspense> | ||
</body> | ||
</html> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
"use client" | ||
import React from "react"; | ||
import FidgetViewer from "@/common/fidgets/FidgetViewer"; | ||
import CompleteFidgets from "@/fidgets"; | ||
import { GenericFidget } from "@/common/fidgets/makeFidget"; | ||
|
||
type PageParams = { | ||
params: { | ||
fidgetName: string; | ||
} | ||
}; | ||
|
||
export default function Page({ params }: PageParams) { | ||
const fidget = CompleteFidgets[params.fidgetName] as GenericFidget; | ||
|
||
return ( | ||
<> | ||
{ | ||
fidget ? <FidgetViewer fidget={fidget} /> : <div>Error Loading Fidget</div> | ||
} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"use client" | ||
import React, { useState } from "react"; | ||
import { FidgetConfig, FidgetSettings, GenericFidget } from "@/common/fidgets/makeFidget"; | ||
import { reduce } from "lodash"; | ||
import { FidgetWrapper, FidgetWrapperConfig } from "@/common/fidgets/FidgetWrapper"; | ||
|
||
|
||
export default function FidgetViewer({ fidget }: { fidget: GenericFidget }) { | ||
const defaultConfig: FidgetWrapperConfig = { | ||
editConfig: fidget.editConfig, | ||
fidgetConfig: { | ||
editable: true, | ||
size: [1, 2], | ||
settings: reduce( | ||
fidget.editConfig.fields, | ||
(acc, f) => ({ | ||
...acc, | ||
[f.fieldName]: f.default || null, | ||
}), | ||
{}, | ||
) | ||
}, | ||
}; | ||
const [config, setConfig] = useState<FidgetWrapperConfig>(defaultConfig); | ||
const saveConifg = async (conf: FidgetConfig<FidgetSettings>) => { | ||
setConfig({ | ||
editConfig: config.editConfig, | ||
fidgetConfig: conf, | ||
}); | ||
return true; | ||
}; | ||
|
||
return ( | ||
<FidgetWrapper | ||
config={config} | ||
saveConfig={saveConifg} | ||
fidget={fidget} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
"use client" | ||
import React, { useState } from "react"; | ||
import { FidgetConfig, FidgetEditConfig, FidgetSettings } from "@/common/fidgets/makeFidget"; | ||
import { Card, CardContent, CardHeader } from "../ui/atoms/card"; | ||
import { Button } from "../ui/atoms/button"; | ||
import FidgetWrapperEditMode from "./FidgetWrapperEditMode"; | ||
import { toast } from "sonner"; | ||
|
||
export type FidgetWrapperConfig = { | ||
fidgetConfig: FidgetConfig<FidgetSettings>; | ||
readonly editConfig: FidgetEditConfig; | ||
}; | ||
|
||
type FidgetWrapperProps = { | ||
fidget: React.FC<FidgetSettings>; | ||
config: FidgetWrapperConfig; | ||
saveConfig: (conf: FidgetConfig<FidgetSettings>) => Promise<boolean> | ||
}; | ||
|
||
export function FidgetWrapper({ fidget, config, saveConfig }: FidgetWrapperProps) { | ||
console.log(fidget); | ||
const [saving, setSaving] = useState(false); | ||
const [editing, setEditing] = useState(false); | ||
const [viewEditor, setViewEditor] = useState(false); | ||
const [localConfig, setLocalConfig] = useState({ | ||
...config.fidgetConfig, | ||
}); | ||
const setSettings = (settings: FidgetSettings) => { | ||
setLocalConfig({ | ||
...localConfig, | ||
settings, | ||
}); | ||
}; | ||
|
||
async function toggleEditing() { | ||
if (editing) { | ||
setSaving(true); | ||
await saveConfig(localConfig) ? setEditing(false) : toast.error("Failed to save fidget settings", { duration: 1000 }); | ||
setSaving(false); | ||
} else { | ||
setEditing(true); | ||
} | ||
} | ||
|
||
// TO DO: Add support for resizing the Fidget | ||
// TO DO: Add support to set size of Fidget to size defined in the config | ||
|
||
return ( | ||
<Card className="max-w-sm col-span-1"> | ||
<CardHeader> | ||
{ | ||
editing ? | ||
<Button | ||
className="w-full" | ||
onClick={() => setViewEditor(!viewEditor)} | ||
> | ||
{ viewEditor ? "View Fidget" : "View Editor" } | ||
</Button> : null | ||
} | ||
{ config.fidgetConfig.editable ? | ||
<Button | ||
className="w-full" | ||
onClick={toggleEditing} | ||
> | ||
{ editing ? "Save": "Edit" } | ||
</Button> : null | ||
} | ||
</CardHeader> | ||
<CardContent> | ||
{ | ||
editing && viewEditor ? | ||
<FidgetWrapperEditMode | ||
editConfig={config.editConfig} | ||
settings={localConfig.settings} | ||
setSettings={setSettings} | ||
/> | ||
: fidget(config.fidgetConfig.settings) | ||
} | ||
</CardContent> | ||
</Card> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from "react"; | ||
import { FidgetEditConfig, FidgetSettings } from "@/common/fidgets/makeFidget"; | ||
|
||
type FidgetWrapperSettingsEditorProps = { | ||
readonly editConfig: FidgetEditConfig; | ||
settings: FidgetSettings; | ||
setSettings: (settings: FidgetSettings) => void; | ||
}; | ||
|
||
const FidgetWrapperSettingsEditor: React.FC<FidgetWrapperSettingsEditorProps> = ({ settings, editConfig, setSettings }) => { | ||
|
||
return (<></>); | ||
}; | ||
|
||
export default FidgetWrapperSettingsEditor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"use client" | ||
import React, { useEffect, useState } from "react"; | ||
import { FidgetConfig, FidgetSettings, Fidget } from "@/common/fidgets/makeFidget"; | ||
import { reduce } from "lodash"; | ||
import { FidgetWrapper, FidgetWrapperConfig } from "@/common/fidgets/FidgetWrapper"; | ||
import { useLazyFidget } from "./useLazyFidget"; | ||
|
||
|
||
export default function LazyFidgetViewer({ fidgetPath }: { fidgetPath: string }) { | ||
// This doesn't work if the FidgetPath is relative | ||
// Building a separate Fidget's package might solve the issue | ||
// But that will take testing | ||
const lazyFidget = useLazyFidget(fidgetPath); | ||
const [config, setConfig] = useState<FidgetWrapperConfig>({ | ||
editConfig: { fields: [], size: { minHeight: 1, maxHeight: 36, minWidth: 1, maxWidth: 36} }, | ||
fidgetConfig: { editable: true, size: [1,1], settings: {} } | ||
}); | ||
const saveConifg = async (conf: FidgetConfig<FidgetSettings>) => { | ||
setConfig({ | ||
editConfig: config.editConfig, | ||
fidgetConfig: conf, | ||
}); | ||
return true; | ||
}; | ||
|
||
useEffect(() => { | ||
if (lazyFidget.status === "Success") { | ||
const fidget = lazyFidget.result; | ||
const defaultConfig: FidgetWrapperConfig = { | ||
editConfig: fidget.editConfig, | ||
fidgetConfig: { | ||
editable: true, | ||
size: [1, 2], | ||
settings: reduce( | ||
fidget.editConfig.fields, | ||
(acc, f) => ({ | ||
...acc, | ||
[f.fieldName]: f.default || null, | ||
}), | ||
{}, | ||
) | ||
}, | ||
}; | ||
setConfig(defaultConfig); | ||
} | ||
}, [lazyFidget]); | ||
|
||
return ( | ||
<> | ||
{ | ||
lazyFidget.status === "Loading" ? | ||
<div>Loading...</div> | ||
: ( | ||
lazyFidget.status === "Success" ? | ||
<FidgetWrapper | ||
config={config} | ||
saveConfig={saveConifg} | ||
fidget={lazyFidget.result} | ||
/> | ||
: <div>Error!</div> | ||
) | ||
} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { NumericRange } from "@/constants/numericRange"; | ||
import React from "react"; | ||
|
||
export interface FidgetSettings { | ||
// TO DO: infer values here backed off the related config file | ||
} | ||
|
||
export type FidgetConfig<S extends FidgetSettings> = { | ||
editable: boolean; | ||
size: [number, number]; | ||
settings: S; | ||
}; | ||
|
||
export type FidgetFieldConfig = { | ||
readonly fieldName: string; | ||
readonly validator?: (value) => boolean; | ||
// This should be changed to a set of allowed input selectors | ||
readonly inputSelector: React.FC; | ||
readonly default?: any; | ||
readonly required: boolean; | ||
}; | ||
|
||
export type FidgetEditConfig = { | ||
fields: FidgetFieldConfig[]; | ||
size: { | ||
minHeight: NumericRange<1,36>; | ||
maxHeight: NumericRange<1,36>; | ||
minWidth: NumericRange<1,36>; | ||
maxWidth: NumericRange<1,36>; | ||
} | ||
}; | ||
|
||
export interface Fidget<P> extends React.FC<P> { | ||
editConfig: FidgetEditConfig; | ||
} | ||
|
||
export type GenericFidget = Fidget<FidgetSettings>; | ||
|
||
export function makeFidget<S>(component: React.FC<S>, editConfig: FidgetEditConfig): Fidget<S> { | ||
const componentAny: any = component; | ||
componentAny.editConfig = editConfig; | ||
return componentAny; | ||
} |
Oops, something went wrong.