Skip to content

Commit

Permalink
prevent flash when search/filter media (ZcashFoundation#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
skyl authored Aug 9, 2023
1 parent f0d51dd commit ecd26dc
Show file tree
Hide file tree
Showing 8 changed files with 286 additions and 269 deletions.
3 changes: 2 additions & 1 deletion py/dj/apps/comments/management/commands/tweet_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ def get_prompt(page_title, headline):
painter = random.choice(painters)
# Form the prompt using elements from the page title, comment headline, and the chosen painter's style
prompt = f"""
'{page_title}, {headline}' by {painter}
An impressionistic painting with no words, characters or glyphs of any kind,
entitled "{page_title}, {headline}" by {painter}
"""
return prompt

Expand Down
494 changes: 244 additions & 250 deletions ts/react/free2z/package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions ts/react/free2z/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@mui/icons-material": "^5.14.3",
"@mui/material": "^5.14.3",
"@mui/material": "^5.14.4",
"@mui/x-date-pickers": "^6.11.0",
"@react-three/cannon": "^6.5.2",
"@react-three/drei": "^9.80.1",
Expand All @@ -17,8 +17,8 @@
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^27.5.2",
"@types/node": "^16.18.39",
"@types/react": "^18.2.18",
"@types/node": "^16.18.40",
"@types/react": "^18.2.19",
"@types/react-dom": "^18.2.7",
"@uiw/react-md-editor": "^3.23.5",
"axios": "^0.26.1",
Expand Down Expand Up @@ -48,7 +48,7 @@
"react-web-share": "^2.0.2",
"redux": "^4.2.1",
"rehype-mathjax": "^4.0.3",
"rehype-prism-plus": "^1.6.2",
"rehype-prism-plus": "^1.6.3",
"rehype-raw": "^6.1.1",
"remark-directive": "^2.0.1",
"remark-gfm": "^3.0.1",
Expand Down
6 changes: 3 additions & 3 deletions ts/react/free2z/src/components/FileImageListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ export function FileItem(props: { file: FileMetadata }) {
>
<ReactPlayer
style={{
width: '100%',
height: 'auto',
// width: '100%',
// height: 'auto',
// maxHeight: '100%',
margin: "0 auto",
// zIndex: 10000,
maxWidth: "150px",
// maxWidth: "100%",
maxHeight: "150px",
maxHeight: "130px",
}}
url={`${file.url}`}
controls={true}
Expand Down
24 changes: 17 additions & 7 deletions ts/react/free2z/src/components/FileSelectorDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const FileSelectorDialog: React.FC<Props> = ({ open, onClose, onSelect }) => {
const [search, setSearch] = useState('');
const [mimeType, setMimeType] = useState('');
const [mql, setMQL] = useState(window.matchMedia('(max-width: 600px)'))
const [initialFetchCompleted, setInitialFetchCompleted] = useState(false);

const manuallySetPageRef = useRef(false);

Expand All @@ -62,6 +63,10 @@ const FileSelectorDialog: React.FC<Props> = ({ open, onClose, onSelect }) => {
onSuccess: (newData: ApiResponse) => {
setData(prev => [...prev, ...newData.results]);
setHasMore(!!newData.next);
setInitialFetchCompleted(true)
},
onError: (err) => {
setInitialFetchCompleted(true)
}
});

Expand Down Expand Up @@ -89,6 +94,7 @@ const FileSelectorDialog: React.FC<Props> = ({ open, onClose, onSelect }) => {
value={search}
onChange={(e) => {
manuallySetPageRef.current = true;
setInitialFetchCompleted(false)
setPage(1);
setSearch(e.target.value);
setData([]);
Expand All @@ -103,6 +109,7 @@ const FileSelectorDialog: React.FC<Props> = ({ open, onClose, onSelect }) => {
value={mimeType}
onChange={(e) => {
manuallySetPageRef.current = true;
setInitialFetchCompleted(false)
setPage(1);
setMimeType(e.target.value as string); // TypeScript type assertion
setData([]);
Expand All @@ -118,20 +125,23 @@ const FileSelectorDialog: React.FC<Props> = ({ open, onClose, onSelect }) => {
</FormControl>
</DialogTitle>

<DialogContent>
{data.length === 0 && (
<DialogContent
sx={{
minHeight: "60vh",
}}
>
{data.length === 0 && initialFetchCompleted && (
<Typography>
No uploads!
Try <Link href="/profile/uploads">uploading</Link> some images.
No results!
You can <Link href="/profile/uploads">upload</Link> some files?
</Typography>
)}
<ImageList
cols={mql.matches ? 2 : 3}
gap={8}
gap={6}
sx={{
minHeight: "80%",
overflowY: 'visible',
}}
// variant="masonry"
>

{data.map((file) => (
Expand Down
6 changes: 6 additions & 0 deletions ts/react/free2z/src/components/MyUploads.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ImageList from '@mui/material/ImageList';
import FileImageListItem from "./FileImageListItem"
import MyUploadsSearch from "./MyUploadsSearch";
import { FeaturedImage } from "./PageRenderer";
import { Typography } from "@mui/material";

type MyUploadsProps = {
loads: number,
Expand All @@ -14,6 +15,7 @@ export default function MyUploads(props: MyUploadsProps) {
const { loads, setLoads } = props
const [results, setResults] = useState([] as FeaturedImage[])
const [mql, setMQL] = useState(window.matchMedia('(max-width: 600px)'))
const [searching, setSearching] = useState(true)

useEffect(() => {
window.addEventListener('resize', () => {
Expand All @@ -24,9 +26,13 @@ export default function MyUploads(props: MyUploadsProps) {
return (
<>
<MyUploadsSearch
setSearching={setSearching}
loads={loads}
setResults={setResults}
/>
{results.length === 0 && !searching &&
<Typography variant="h6" sx={{ textAlign: "center" }}>No results</Typography>
}
<ImageList
cols={mql.matches ? 2 : 3}
variant="masonry"
Expand Down
10 changes: 7 additions & 3 deletions ts/react/free2z/src/components/MyUploadsSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ type MyUploadsSearchProps = {
loads?: number
setResults: React.Dispatch<React.SetStateAction<FeaturedImage[]>>
extraQuery?: string
setSearching: React.Dispatch<React.SetStateAction<boolean>>
}

export default function MyUploadsSearch(props: MyUploadsSearchProps) {
const { loads, setResults, extraQuery } = props
const { loads, setResults, extraQuery, setSearching } = props
const [prev, setPrev] = useState(null)
const [next, setNext] = useState(null)
const [page, setPage] = useState(1)
Expand All @@ -25,6 +26,7 @@ export default function MyUploadsSearch(props: MyUploadsSearchProps) {
};

useEffect(() => {
setSearching(true)
setResults([] as FeaturedImage[])
axios.get(
`/api/myuploads/?page=${page}&search=${search}&${extraQuery}`
Expand All @@ -34,9 +36,11 @@ export default function MyUploadsSearch(props: MyUploadsSearchProps) {
setCount(res.data.count)
setPrev(res.data.previous)
setNext(res.data.next)
setSearching(false)
}).catch((err) => {
console.error("Failed to search", err)
setSearching(false)
})
// catch? ;/
// snack
}, [loads, page, search])

return (
Expand Down
4 changes: 3 additions & 1 deletion ts/react/free2z/src/components/UploadOrSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function UploadOrSelect(props: UploadOrSelectProps) {
const [openDialog, setOpenDialog] = useState(false);
const [prog, setProgress] = useState(0)
const [mql, setMQL] = useState(window.matchMedia('(max-width: 600px)'))
const [searching, setSearching] = useState(true)

const handleUpload = (
event: ChangeEvent<HTMLInputElement>,
Expand Down Expand Up @@ -170,12 +171,13 @@ export default function UploadOrSelect(props: UploadOrSelectProps) {
>
<DialogTitle>
<MyUploadsSearch
setSearching={setSearching}
setResults={setResults}
extraQuery={"access=public&mime_type=image"}
/>
</DialogTitle>
<DialogContent>
{results.length === 0 && (
{results.length === 0 && !searching && (
<Typography>
No uploads!
Try <Link href="/profile/uploads">uploading</Link> some images.
Expand Down

0 comments on commit ecd26dc

Please sign in to comment.