MediaAttachmentGrid: support click to reveal
This commit is contained in:
		
							parent
							
								
									1047a3b10d
								
							
						
					
					
						commit
						8cd95b9e90
					
				
					 2 changed files with 38 additions and 10 deletions
				
			
		| 
						 | 
					@ -6,16 +6,6 @@
 | 
				
			||||||
  gap: 4px;
 | 
					  gap: 4px;
 | 
				
			||||||
  contain: layout style;
 | 
					  contain: layout style;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  &.sensitive>.cell> :where(img, video) {
 | 
					 | 
				
			||||||
    filter: blur(20px) saturate(0.2);
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  >.cell> :where(img, video) {
 | 
					 | 
				
			||||||
    object-fit: contain;
 | 
					 | 
				
			||||||
    width: 100%;
 | 
					 | 
				
			||||||
    height: 100%;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  >.cell {
 | 
					  >.cell {
 | 
				
			||||||
    max-height: 35vh;
 | 
					    max-height: 35vh;
 | 
				
			||||||
    min-height: 40px;
 | 
					    min-height: 40px;
 | 
				
			||||||
| 
						 | 
					@ -33,5 +23,17 @@
 | 
				
			||||||
      outline: 8px solid var(--media-color-accent, var(--tutu-color-surface-d));
 | 
					      outline: 8px solid var(--media-color-accent, var(--tutu-color-surface-d));
 | 
				
			||||||
      border-color: var(--media-color-accent, var(--tutu-color-surface-d));
 | 
					      border-color: var(--media-color-accent, var(--tutu-color-surface-d));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    & > :where(img, video, .sensitive-placeholder) {
 | 
				
			||||||
 | 
					      object-fit: contain;
 | 
				
			||||||
 | 
					      width: 100%;
 | 
				
			||||||
 | 
					      height: 100%;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    & > .sensitive-placeholder {
 | 
				
			||||||
 | 
					      display: flex;
 | 
				
			||||||
 | 
					      align-items: center;
 | 
				
			||||||
 | 
					      justify-content: center;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -8,6 +8,7 @@ import {
 | 
				
			||||||
  createRenderEffect,
 | 
					  createRenderEffect,
 | 
				
			||||||
  createSignal,
 | 
					  createSignal,
 | 
				
			||||||
  onCleanup,
 | 
					  onCleanup,
 | 
				
			||||||
 | 
					  untrack,
 | 
				
			||||||
} from "solid-js";
 | 
					} from "solid-js";
 | 
				
			||||||
import MediaViewer from "./MediaViewer";
 | 
					import MediaViewer from "./MediaViewer";
 | 
				
			||||||
import { render } from "solid-js/web";
 | 
					import { render } from "solid-js/web";
 | 
				
			||||||
| 
						 | 
					@ -20,6 +21,8 @@ import { $settings } from "../settings/stores";
 | 
				
			||||||
import { averageColorHex } from "../platform/blurhash";
 | 
					import { averageColorHex } from "../platform/blurhash";
 | 
				
			||||||
import "./MediaAttachmentGrid.css";
 | 
					import "./MediaAttachmentGrid.css";
 | 
				
			||||||
import cardStyle from "../material/cards.module.css";
 | 
					import cardStyle from "../material/cards.module.css";
 | 
				
			||||||
 | 
					import { Preview } from "@suid/icons-material";
 | 
				
			||||||
 | 
					import { IconButton } from "@suid/material";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type ElementSize = { width: number; height: number };
 | 
					type ElementSize = { width: number; height: number };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -58,6 +61,7 @@ const MediaAttachmentGrid: Component<{
 | 
				
			||||||
  const viewerOpened = () => typeof viewerIndex() !== "undefined";
 | 
					  const viewerOpened = () => typeof viewerIndex() !== "undefined";
 | 
				
			||||||
  const settings = useStore($settings);
 | 
					  const settings = useStore($settings);
 | 
				
			||||||
  const windowSize = useWindowSize();
 | 
					  const windowSize = useWindowSize();
 | 
				
			||||||
 | 
					  const [reveal, setReveal] = createSignal([] as number[]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  createRenderEffect(() => {
 | 
					  createRenderEffect(() => {
 | 
				
			||||||
    const vidx = viewerIndex();
 | 
					    const vidx = viewerIndex();
 | 
				
			||||||
| 
						 | 
					@ -134,6 +138,16 @@ const MediaAttachmentGrid: Component<{
 | 
				
			||||||
      accentColor ? { "--media-color-accent": accentColor } : {},
 | 
					      accentColor ? { "--media-color-accent": accentColor } : {},
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const isReveal = (idx: number) => {
 | 
				
			||||||
 | 
					    return reveal().includes(idx);
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const addReveal = (idx: number) => {
 | 
				
			||||||
 | 
					    if (!untrack(() => isReveal(idx))) {
 | 
				
			||||||
 | 
					      setReveal((x) => [...x, idx]);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <section
 | 
					    <section
 | 
				
			||||||
      ref={setRootRef}
 | 
					      ref={setRootRef}
 | 
				
			||||||
| 
						 | 
					@ -156,6 +170,18 @@ const MediaAttachmentGrid: Component<{
 | 
				
			||||||
              data-media-type={item().type}
 | 
					              data-media-type={item().type}
 | 
				
			||||||
            >
 | 
					            >
 | 
				
			||||||
              <Switch>
 | 
					              <Switch>
 | 
				
			||||||
 | 
					                <Match when={props.sensitive && !isReveal(index)}>
 | 
				
			||||||
 | 
					                  <div class="sensitive-placeholder">
 | 
				
			||||||
 | 
					                    <IconButton
 | 
				
			||||||
 | 
					                      color="inherit"
 | 
				
			||||||
 | 
					                      size="large"
 | 
				
			||||||
 | 
					                      onClick={[addReveal, index]}
 | 
				
			||||||
 | 
					                      aria-label="Reveal this media"
 | 
				
			||||||
 | 
					                    >
 | 
				
			||||||
 | 
					                      <Preview />
 | 
				
			||||||
 | 
					                    </IconButton>
 | 
				
			||||||
 | 
					                  </div>
 | 
				
			||||||
 | 
					                </Match>
 | 
				
			||||||
                <Match when={itemType() === "image"}>
 | 
					                <Match when={itemType() === "image"}>
 | 
				
			||||||
                  <img
 | 
					                  <img
 | 
				
			||||||
                    src={item().previewUrl}
 | 
					                    src={item().previewUrl}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue