-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gui): share image history between tabs, add setting to adjust le…
…ngth of history (fixes #22)
- Loading branch information
Showing
8 changed files
with
137 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { mustExist } from '@apextoaster/js-utils'; | ||
import { Grid } from '@mui/material'; | ||
import { useContext } from 'react'; | ||
import * as React from 'react'; | ||
import { useStore } from 'zustand'; | ||
|
||
import { ApiResponse } from '../api/client.js'; | ||
import { StateContext } from '../main.js'; | ||
import { ImageCard } from './ImageCard.js'; | ||
import { LoadingCard } from './LoadingCard.js'; | ||
|
||
export function ImageHistory() { | ||
const state = useStore(mustExist(useContext(StateContext))); | ||
const { images } = state.history; | ||
|
||
const children = []; | ||
|
||
if (state.history.loading) { | ||
children.push(<LoadingCard height={512} width={512} />); // TODO: get dimensions from config | ||
} | ||
|
||
function removeHistory(image: ApiResponse) { | ||
state.setHistory(images.filter((item) => image.output !== item.output)); | ||
} | ||
|
||
if (images.length > 0) { | ||
children.push(...images.map((item) => <ImageCard value={item} onDelete={removeHistory} />)); | ||
} else { | ||
if (state.history.loading === false) { | ||
children.push(<div>No results. Press Generate.</div>); | ||
} | ||
} | ||
|
||
const limited = children.slice(0, state.history.limit); | ||
|
||
return <Grid container spacing={2}>{limited.map((child, idx) => <Grid item key={idx} xs={6}>{child}</Grid>)}</Grid>; | ||
} |
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
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 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