feat: the last commit of year
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { IColumn } from "@lume/types";
|
||||
import { COL_TYPES } from "@lume/utils";
|
||||
import { NDKEvent } from "@nostr-dev-kit/ndk";
|
||||
import {
|
||||
ReactNode,
|
||||
createContext,
|
||||
@@ -13,9 +12,10 @@ import { useStorage } from "../../provider";
|
||||
|
||||
type ColumnContext = {
|
||||
columns: IColumn[];
|
||||
addColumn: (column: IColumn) => void;
|
||||
removeColumn: (id: string) => void;
|
||||
loadAllColumns: () => void;
|
||||
addColumn: (column: IColumn) => Promise<void>;
|
||||
removeColumn: (id: number) => Promise<void>;
|
||||
moveColumn: (id: number, position: "left" | "right") => void;
|
||||
loadAllColumns: () => Promise<IColumn[]>;
|
||||
};
|
||||
|
||||
const ColumnContext = createContext<ColumnContext>(null);
|
||||
@@ -24,7 +24,7 @@ export function ColumnProvider({ children }: { children: ReactNode }) {
|
||||
const storage = useStorage();
|
||||
const [columns, setColumns] = useState<IColumn[]>([
|
||||
{
|
||||
id: "9999",
|
||||
id: 9999,
|
||||
title: "Newsfeed",
|
||||
content: "",
|
||||
kind: COL_TYPES.newsfeed,
|
||||
@@ -44,11 +44,28 @@ export function ColumnProvider({ children }: { children: ReactNode }) {
|
||||
if (result) setColumns((prev) => [...prev, column]);
|
||||
}, []);
|
||||
|
||||
const removeColumn = useCallback(async (id: string) => {
|
||||
const removeColumn = useCallback(async (id: number) => {
|
||||
await storage.removeWidget(id);
|
||||
setColumns((prev) => prev.filter((t) => t.id !== id));
|
||||
}, []);
|
||||
|
||||
const moveColumn = useCallback(
|
||||
(id: number, position: "left" | "right") => {
|
||||
const newCols = [...columns];
|
||||
|
||||
const col = newCols.find((el) => el.id === id);
|
||||
const colIndex = newCols.findIndex((el) => el.id === id);
|
||||
|
||||
newCols.splice(colIndex, 1);
|
||||
|
||||
if (position === "left") newCols.splice(colIndex - 1, 0, col);
|
||||
if (position === "right") newCols.splice(colIndex + 1, 0, col);
|
||||
|
||||
setColumns(newCols);
|
||||
},
|
||||
[columns],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
let isMounted = true;
|
||||
|
||||
@@ -63,7 +80,7 @@ export function ColumnProvider({ children }: { children: ReactNode }) {
|
||||
|
||||
return (
|
||||
<ColumnContext.Provider
|
||||
value={{ columns, addColumn, removeColumn, loadAllColumns }}
|
||||
value={{ columns, addColumn, removeColumn, moveColumn, loadAllColumns }}
|
||||
>
|
||||
{children}
|
||||
</ColumnContext.Provider>
|
||||
|
||||
Reference in New Issue
Block a user