chore: clean up repo for public release
- Remove BMAD framework, IDE configs, dev screenshots, test files, internal docs, and backup files - Rename keep-notes/ to memento-note/ - Update all references from keep-notes to memento-note - Add Apache 2.0 license with Commons Clause (non-commercial restriction) - Add clean .gitignore and .env.docker.example
This commit is contained in:
147
memento-note/context/LabelContext.tsx
Normal file
147
memento-note/context/LabelContext.tsx
Normal file
@@ -0,0 +1,147 @@
|
||||
'use client'
|
||||
|
||||
import { createContext, useContext, useState, useEffect, ReactNode } from 'react'
|
||||
import { LabelColorName, LABEL_COLORS } from '@/lib/types'
|
||||
import { getHashColor } from '@/lib/utils'
|
||||
|
||||
export interface Label {
|
||||
id: string
|
||||
name: string
|
||||
color: LabelColorName
|
||||
userId?: string | null
|
||||
createdAt: Date
|
||||
updatedAt: Date
|
||||
}
|
||||
|
||||
interface LabelContextType {
|
||||
labels: Label[]
|
||||
loading: boolean
|
||||
notebookId?: string | null
|
||||
setNotebookId: (notebookId: string | null) => void
|
||||
addLabel: (name: string, color?: LabelColorName, notebookId?: string | null) => Promise<void>
|
||||
updateLabel: (id: string, updates: Partial<Pick<Label, 'name' | 'color'>>) => Promise<void>
|
||||
deleteLabel: (id: string) => Promise<void>
|
||||
getLabelColor: (name: string) => LabelColorName
|
||||
refreshLabels: () => Promise<void>
|
||||
}
|
||||
|
||||
const LabelContext = createContext<LabelContextType | undefined>(undefined)
|
||||
|
||||
export function LabelProvider({ children }: { children: ReactNode }) {
|
||||
const [labels, setLabels] = useState<Label[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [notebookId, setNotebookId] = useState<string | null>(null)
|
||||
|
||||
const fetchLabels = async () => {
|
||||
try {
|
||||
setLoading(true)
|
||||
// Build URL with notebookId filter
|
||||
const url = new URL('/api/labels', window.location.origin)
|
||||
if (notebookId) {
|
||||
url.searchParams.set('notebookId', notebookId)
|
||||
}
|
||||
|
||||
const response = await fetch(url.toString(), {
|
||||
cache: 'no-store',
|
||||
credentials: 'include'
|
||||
})
|
||||
const data = await response.json()
|
||||
if (data.success && data.data) {
|
||||
setLabels(data.data)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch labels:', error)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
// Re-fetch labels when notebookId changes
|
||||
useEffect(() => {
|
||||
fetchLabels()
|
||||
}, [notebookId])
|
||||
|
||||
const addLabel = async (name: string, color?: LabelColorName, labelNotebookId?: string | null) => {
|
||||
try {
|
||||
const labelColor = color || getHashColor(name);
|
||||
const finalNotebookId = labelNotebookId || notebookId
|
||||
|
||||
const response = await fetch('/api/labels', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name, color: labelColor, notebookId: finalNotebookId }),
|
||||
})
|
||||
const data = await response.json()
|
||||
if (data.success && data.data) {
|
||||
setLabels(prev => [...prev, data.data])
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to add label:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
const updateLabel = async (id: string, updates: Partial<Pick<Label, 'name' | 'color'>>) => {
|
||||
try {
|
||||
const response = await fetch(`/api/labels/${id}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(updates),
|
||||
})
|
||||
const data = await response.json()
|
||||
if (data.success && data.data) {
|
||||
setLabels(prev => prev.map(label =>
|
||||
label.id === id ? { ...label, ...data.data } : label
|
||||
))
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to update label:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
const deleteLabel = async (id: string) => {
|
||||
try {
|
||||
const response = await fetch(`/api/labels/${id}`, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
if (response.ok) {
|
||||
setLabels(prev => prev.filter(label => label.id !== id))
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to delete label:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
const getLabelColorHelper = (name: string): LabelColorName => {
|
||||
const label = labels.find(l => l.name.toLowerCase() === name.toLowerCase())
|
||||
return label?.color || 'gray'
|
||||
}
|
||||
|
||||
const refreshLabels = async () => {
|
||||
await fetchLabels()
|
||||
}
|
||||
|
||||
const value: LabelContextType = {
|
||||
labels,
|
||||
loading,
|
||||
notebookId,
|
||||
setNotebookId,
|
||||
addLabel,
|
||||
updateLabel,
|
||||
deleteLabel,
|
||||
getLabelColor: getLabelColorHelper,
|
||||
refreshLabels,
|
||||
}
|
||||
|
||||
return <LabelContext.Provider value={value}>{children}</LabelContext.Provider>
|
||||
}
|
||||
|
||||
export function useLabels() {
|
||||
const context = useContext(LabelContext)
|
||||
if (context === undefined) {
|
||||
throw new Error('useLabels must be used within a LabelProvider')
|
||||
}
|
||||
return context
|
||||
}
|
||||
32
memento-note/context/NoteRefreshContext.tsx
Normal file
32
memento-note/context/NoteRefreshContext.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
'use client'
|
||||
|
||||
import { createContext, useContext, useState, useCallback } from 'react'
|
||||
|
||||
interface NoteRefreshContextType {
|
||||
refreshKey: number
|
||||
triggerRefresh: () => void
|
||||
}
|
||||
|
||||
const NoteRefreshContext = createContext<NoteRefreshContextType | undefined>(undefined)
|
||||
|
||||
export function NoteRefreshProvider({ children }: { children: React.ReactNode }) {
|
||||
const [refreshKey, setRefreshKey] = useState(0)
|
||||
|
||||
const triggerRefresh = useCallback(() => {
|
||||
setRefreshKey(prev => prev + 1)
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<NoteRefreshContext.Provider value={{ refreshKey, triggerRefresh }}>
|
||||
{children}
|
||||
</NoteRefreshContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export function useNoteRefresh() {
|
||||
const context = useContext(NoteRefreshContext)
|
||||
if (!context) {
|
||||
throw new Error('useNoteRefresh must be used within NoteRefreshProvider')
|
||||
}
|
||||
return context
|
||||
}
|
||||
36
memento-note/context/home-view-context.tsx
Normal file
36
memento-note/context/home-view-context.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
'use client'
|
||||
|
||||
import { createContext, useContext, useMemo, useState, type ReactNode } from 'react'
|
||||
|
||||
export type HomeUiControls = {
|
||||
isTabsMode: boolean
|
||||
openNoteComposer: () => void
|
||||
}
|
||||
|
||||
type Ctx = {
|
||||
controls: HomeUiControls | null
|
||||
setControls: (c: HomeUiControls | null) => void
|
||||
}
|
||||
|
||||
const HomeViewContext = createContext<Ctx | null>(null)
|
||||
|
||||
export function HomeViewProvider({ children }: { children: ReactNode }) {
|
||||
const [controls, setControls] = useState<HomeUiControls | null>(null)
|
||||
const value = useMemo(() => ({ controls, setControls }), [controls])
|
||||
|
||||
return <HomeViewContext.Provider value={value}>{children}</HomeViewContext.Provider>
|
||||
}
|
||||
|
||||
/** Enregistré par la page d’accueil ; la sidebar lit `controls` */
|
||||
export function useHomeView() {
|
||||
const ctx = useContext(HomeViewContext)
|
||||
if (!ctx) {
|
||||
throw new Error('useHomeView must be used within HomeViewProvider')
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
|
||||
/** Sidebar / shells : ne pas planter si hors provider */
|
||||
export function useHomeViewOptional(): Ctx | null {
|
||||
return useContext(HomeViewContext)
|
||||
}
|
||||
64
memento-note/context/notebook-drag-context.tsx
Normal file
64
memento-note/context/notebook-drag-context.tsx
Normal file
@@ -0,0 +1,64 @@
|
||||
'use client'
|
||||
|
||||
import { createContext, useContext, useState, useCallback, ReactNode } from 'react'
|
||||
|
||||
interface NotebookDragContextValue {
|
||||
draggedNoteId: string | null
|
||||
dragOverNotebookId: string | null
|
||||
startDrag: (noteId: string) => void
|
||||
endDrag: () => void
|
||||
dragOver: (notebookId: string | null) => void
|
||||
isDragging: boolean
|
||||
isDragOver: boolean
|
||||
}
|
||||
|
||||
const NotebookDragContext = createContext<NotebookDragContextValue | null>(null)
|
||||
|
||||
export function useNotebookDrag() {
|
||||
const context = useContext(NotebookDragContext)
|
||||
if (!context) {
|
||||
throw new Error('useNotebookDrag must be used within NotebookDragProvider')
|
||||
}
|
||||
return context
|
||||
}
|
||||
|
||||
interface NotebookDragProviderProps {
|
||||
children: ReactNode
|
||||
}
|
||||
|
||||
export function NotebookDragProvider({ children }: NotebookDragProviderProps) {
|
||||
const [draggedNoteId, setDraggedNoteId] = useState<string | null>(null)
|
||||
const [dragOverNotebookId, setDragOverNotebookId] = useState<string | null>(null)
|
||||
|
||||
const startDrag = useCallback((noteId: string) => {
|
||||
setDraggedNoteId(noteId)
|
||||
}, [])
|
||||
|
||||
const endDrag = useCallback(() => {
|
||||
setDraggedNoteId(null)
|
||||
setDragOverNotebookId(null)
|
||||
}, [])
|
||||
|
||||
const dragOver = useCallback((notebookId: string | null) => {
|
||||
setDragOverNotebookId(notebookId)
|
||||
}, [])
|
||||
|
||||
const isDragging = draggedNoteId !== null
|
||||
const isDragOver = dragOverNotebookId !== null
|
||||
|
||||
return (
|
||||
<NotebookDragContext.Provider
|
||||
value={{
|
||||
draggedNoteId,
|
||||
dragOverNotebookId,
|
||||
startDrag,
|
||||
endDrag,
|
||||
dragOver,
|
||||
isDragging,
|
||||
isDragOver,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</NotebookDragContext.Provider>
|
||||
)
|
||||
}
|
||||
296
memento-note/context/notebooks-context.tsx
Normal file
296
memento-note/context/notebooks-context.tsx
Normal file
@@ -0,0 +1,296 @@
|
||||
'use client'
|
||||
|
||||
import { createContext, useContext, useState, useEffect, useMemo, useCallback } from 'react'
|
||||
import type { Notebook, Label, Note } from '@/lib/types'
|
||||
import { useNoteRefresh } from './NoteRefreshContext'
|
||||
import { toast } from 'sonner'
|
||||
|
||||
// ===== INPUT TYPES =====
|
||||
export interface CreateNotebookInput {
|
||||
name: string
|
||||
icon?: string
|
||||
color?: string
|
||||
}
|
||||
|
||||
export interface UpdateNotebookInput {
|
||||
name?: string
|
||||
icon?: string
|
||||
color?: string
|
||||
}
|
||||
|
||||
export interface CreateLabelInput {
|
||||
name: string
|
||||
color?: string
|
||||
notebookId: string
|
||||
}
|
||||
|
||||
export interface UpdateLabelInput {
|
||||
name?: string
|
||||
color?: string
|
||||
}
|
||||
|
||||
// ===== CONTEXT VALUE =====
|
||||
export interface NotebooksContextValue {
|
||||
// État global
|
||||
notebooks: Notebook[]
|
||||
currentNotebook: Notebook | null // null = "Notes générales"
|
||||
currentLabels: Label[] // Labels du notebook actuel
|
||||
isLoading: boolean
|
||||
isMovingNote: boolean
|
||||
error: string | null
|
||||
|
||||
// Actions: Notebooks
|
||||
createNotebookOptimistic: (data: CreateNotebookInput) => Promise<void>
|
||||
updateNotebook: (notebookId: string, data: UpdateNotebookInput) => Promise<void>
|
||||
deleteNotebook: (notebookId: string) => Promise<void>
|
||||
updateNotebookOrderOptimistic: (notebookIds: string[]) => Promise<void>
|
||||
setCurrentNotebook: (notebook: Notebook | null) => void
|
||||
|
||||
// Actions: Labels
|
||||
createLabel: (data: CreateLabelInput) => Promise<Label>
|
||||
updateLabel: (labelId: string, data: UpdateLabelInput) => Promise<void>
|
||||
deleteLabel: (labelId: string) => Promise<void>
|
||||
|
||||
// Actions: Notes
|
||||
moveNoteToNotebookOptimistic: (noteId: string, notebookId: string | null) => Promise<void>
|
||||
|
||||
/** Recharger la liste des carnets (ex. après maintenance étiquettes) */
|
||||
refreshNotebooks: () => Promise<void>
|
||||
|
||||
// Actions: AI (stubs pour l'instant)
|
||||
suggestNotebookForNote: (noteContent: string) => Promise<Notebook | null>
|
||||
suggestLabelsForNote: (noteContent: string, notebookId: string) => Promise<string[]>
|
||||
}
|
||||
|
||||
export const NotebooksContext = createContext<NotebooksContextValue | null>(null)
|
||||
|
||||
export function useNotebooks() {
|
||||
const context = useContext(NotebooksContext)
|
||||
if (!context) {
|
||||
throw new Error('useNotebooks must be used within NotebooksProvider')
|
||||
}
|
||||
return context
|
||||
}
|
||||
|
||||
interface NotebooksProviderProps {
|
||||
children: React.ReactNode
|
||||
initialNotebooks?: Notebook[]
|
||||
}
|
||||
|
||||
export function NotebooksProvider({ children, initialNotebooks = [] }: NotebooksProviderProps) {
|
||||
// ===== BASE STATE =====
|
||||
const [notebooks, setNotebooks] = useState<Notebook[]>(initialNotebooks)
|
||||
const [currentNotebook, setCurrentNotebook] = useState<Notebook | null>(null)
|
||||
const [isLoading, setIsLoading] = useState(true)
|
||||
const [isMovingNote, setIsMovingNote] = useState(false)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const { triggerRefresh } = useNoteRefresh() // Get triggerRefresh from context
|
||||
|
||||
// ===== DERIVED STATE =====
|
||||
const currentLabels = useMemo(() => {
|
||||
if (!currentNotebook) return []
|
||||
return notebooks.find(nb => nb.id === currentNotebook.id)?.labels ?? []
|
||||
}, [currentNotebook, notebooks])
|
||||
|
||||
// ===== DATA LOADING =====
|
||||
const loadNotebooks = useCallback(async () => {
|
||||
setIsLoading(true)
|
||||
setError(null)
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/notebooks')
|
||||
if (!response.ok) throw new Error('Failed to load notebooks')
|
||||
|
||||
const data = await response.json()
|
||||
setNotebooks(data.notebooks || [])
|
||||
} catch (err) {
|
||||
console.error('Failed to load notebooks:', err)
|
||||
setError(err instanceof Error ? err.message : 'Unknown error')
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
loadNotebooks()
|
||||
}, [loadNotebooks])
|
||||
|
||||
// ===== ACTIONS: NOTEBOOKS =====
|
||||
const createNotebookOptimistic = useCallback(async (data: CreateNotebookInput) => {
|
||||
const response = await fetch('/api/notebooks', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to create notebook')
|
||||
}
|
||||
|
||||
// Reload notebooks from server to update sidebar state
|
||||
await loadNotebooks()
|
||||
triggerRefresh()
|
||||
}, [loadNotebooks, triggerRefresh])
|
||||
|
||||
const updateNotebook = useCallback(async (notebookId: string, data: UpdateNotebookInput) => {
|
||||
const response = await fetch(`/api/notebooks/${notebookId}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to update notebook')
|
||||
}
|
||||
|
||||
await loadNotebooks()
|
||||
triggerRefresh()
|
||||
}, [loadNotebooks, triggerRefresh])
|
||||
|
||||
const deleteNotebook = useCallback(async (notebookId: string) => {
|
||||
const response = await fetch(`/api/notebooks/${notebookId}`, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to delete notebook')
|
||||
}
|
||||
|
||||
await loadNotebooks()
|
||||
triggerRefresh()
|
||||
}, [loadNotebooks, triggerRefresh])
|
||||
|
||||
const updateNotebookOrderOptimistic = useCallback(async (notebookIds: string[]) => {
|
||||
const response = await fetch('/api/notebooks/reorder', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ notebookIds }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to update notebook order')
|
||||
}
|
||||
|
||||
await loadNotebooks()
|
||||
triggerRefresh()
|
||||
}, [loadNotebooks, triggerRefresh])
|
||||
|
||||
// ===== ACTIONS: LABELS =====
|
||||
const createLabel = useCallback(async (data: CreateLabelInput) => {
|
||||
const response = await fetch('/api/labels', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to create label')
|
||||
}
|
||||
|
||||
const result = await response.json()
|
||||
return result
|
||||
}, [])
|
||||
|
||||
const updateLabel = useCallback(async (labelId: string, data: UpdateLabelInput) => {
|
||||
const response = await fetch(`/api/labels/${labelId}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to update label')
|
||||
}
|
||||
}, [])
|
||||
|
||||
const deleteLabel = useCallback(async (labelId: string) => {
|
||||
const response = await fetch(`/api/labels/${labelId}`, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to delete label')
|
||||
}
|
||||
}, [])
|
||||
|
||||
// ===== ACTIONS: NOTES =====
|
||||
const moveNoteToNotebookOptimistic = useCallback(async (noteId: string, notebookId: string | null) => {
|
||||
setIsMovingNote(true)
|
||||
try {
|
||||
const response = await fetch(`/api/notes/${noteId}/move`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ notebookId }),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to move note')
|
||||
}
|
||||
|
||||
await loadNotebooks()
|
||||
triggerRefresh()
|
||||
} catch (error) {
|
||||
toast.error('Failed to move note. Please try again.')
|
||||
throw error
|
||||
} finally {
|
||||
setIsMovingNote(false)
|
||||
}
|
||||
}, [loadNotebooks, triggerRefresh])
|
||||
|
||||
// ===== ACTIONS: AI (STUBS) =====
|
||||
const suggestNotebookForNote = useCallback(async (_noteContent: string) => {
|
||||
// Stub pour l'instant - retourne null
|
||||
return null
|
||||
}, [])
|
||||
|
||||
const suggestLabelsForNote = useCallback(async (_noteContent: string, _notebookId: string) => {
|
||||
// Stub pour l'instant - retourne tableau vide
|
||||
return []
|
||||
}, [])
|
||||
|
||||
// ===== CONTEXT VALUE =====
|
||||
const value: NotebooksContextValue = useMemo(() => ({
|
||||
notebooks,
|
||||
currentNotebook,
|
||||
currentLabels,
|
||||
isLoading,
|
||||
isMovingNote,
|
||||
error,
|
||||
createNotebookOptimistic,
|
||||
updateNotebook,
|
||||
deleteNotebook,
|
||||
updateNotebookOrderOptimistic,
|
||||
setCurrentNotebook,
|
||||
createLabel,
|
||||
updateLabel,
|
||||
deleteLabel,
|
||||
moveNoteToNotebookOptimistic,
|
||||
refreshNotebooks: loadNotebooks,
|
||||
suggestNotebookForNote,
|
||||
suggestLabelsForNote,
|
||||
}), [
|
||||
notebooks,
|
||||
currentNotebook,
|
||||
currentLabels,
|
||||
isLoading,
|
||||
isMovingNote,
|
||||
error,
|
||||
createNotebookOptimistic,
|
||||
updateNotebook,
|
||||
deleteNotebook,
|
||||
updateNotebookOrderOptimistic,
|
||||
createLabel,
|
||||
updateLabel,
|
||||
deleteLabel,
|
||||
moveNoteToNotebookOptimistic,
|
||||
loadNotebooks,
|
||||
suggestNotebookForNote,
|
||||
suggestLabelsForNote,
|
||||
])
|
||||
|
||||
return (
|
||||
<NotebooksContext.Provider value={value}>
|
||||
{children}
|
||||
</NotebooksContext.Provider>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user