Skip to content

Commit

Permalink
Various tweeks
Browse files Browse the repository at this point in the history
  • Loading branch information
robrotheram committed Jan 2, 2024
1 parent 6bc7107 commit a6ad8bd
Show file tree
Hide file tree
Showing 16 changed files with 224 additions and 80 deletions.
21 changes: 16 additions & 5 deletions backend/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,29 @@ func (api *GoGalleryAPI) setupDashboardRoutes() {
}

func (api *GoGalleryAPI) ImgHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "max-age=604800") // 7 days
size := r.URL.Query().Get("size")
vars := mux.Vars(r)
id := vars["id"]
if len(size) == 0 {
size = vars["size"]
}
pic := api.db.Pictures.FindByID(id)
//Is image in cache
if file, err := api.db.ImageCache.Get(pic.Id, size); err == nil {
io.Copy(w, file)
return
}
src, err := pic.Load()
if err != nil {
return
}
pipeline.ProcessImage(src, templateengine.ImageSizes["xsmall"], w)
cache, _ := api.db.ImageCache.Writer(pic.Id, size)
writer := io.MultiWriter(w, cache)
if size, ok := templateengine.ImageSizes[size]; ok {
pipeline.ProcessImage(src, size, writer)
return
}
pipeline.ProcessImage(src, templateengine.ImageSizes["xsmall"], writer)
}

func (api *GoGalleryAPI) DashboardAPI() {
Expand Down Expand Up @@ -171,7 +185,6 @@ func IsHtml(constentType string) bool {

func (h *home) ServeHTTP(w http.ResponseWriter, r *http.Request) {
data := strings.Replace(r.URL.Path, "/preview-build", "", -1)

data = path.Join(h.base, data)
fileInfo, err := os.Stat(data)
if err != nil {
Expand All @@ -180,7 +193,6 @@ func (h *home) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if fileInfo.IsDir() {
data = path.Join(data, "index.html")
}
fmt.Println(data)
file, err := os.Open(data)
if err != nil {
return
Expand All @@ -197,5 +209,4 @@ func (h *home) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", contentType)
io.Copy(w, file)
}

}
1 change: 1 addition & 0 deletions backend/cmd/dasboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func LaunchDashboard() error {
Height: 768,
MinWidth: 1200,
Assets: &embeds.DashboardFS,
Frameless: false,
BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
})
}
14 changes: 8 additions & 6 deletions backend/datastore/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ type CRUD interface {
}

type DataStore struct {
db *storm.DB
Pictures *PictureCollection
Albums *AlumnCollectioins
db *storm.DB
Pictures *PictureCollection
Albums *AlumnCollectioins
ImageCache *ImageCache
}

func Open(dbPath string) *DataStore {
Expand All @@ -36,9 +37,10 @@ func Open(dbPath string) *DataStore {
log.Fatalf("Unable to open db at: %s \n Error: %v", path, err)
}
return &DataStore{
db: db,
Pictures: &PictureCollection{DB: db},
Albums: &AlumnCollectioins{DB: db},
db: db,
Pictures: &PictureCollection{DB: db},
Albums: &AlumnCollectioins{DB: db},
ImageCache: NewImageCache(),
}
}

Expand Down
26 changes: 26 additions & 0 deletions backend/datastore/image_cache.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package datastore

import (
"fmt"
"os"
"path"
)

type ImageCache struct {
base string
}

func NewImageCache() *ImageCache {
path := path.Join(os.TempDir(), "gogallery")
os.MkdirAll(path, 0755)
return &ImageCache{
base: path,
}
}

func (ic *ImageCache) Get(name string, size string) (*os.File, error) {
return os.Open(path.Join(ic.base, fmt.Sprintf("%s-%s.webp", name, size)))
}
func (ic *ImageCache) Writer(name string, size string) (*os.File, error) {
return os.Create(path.Join(ic.base, fmt.Sprintf("%s-%s.webp", name, size)))
}
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

</head>
<body style="margin: 0px;">
<div id="app_root"></div>
<div id="app_root" style="--wails-draggable:drag"></div>
<script src="./src/main.jsx" type="module"></script>
</body>
</html>
Expand Down
88 changes: 62 additions & 26 deletions frontend/src/components/Gallery.jsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,69 @@
import React from 'react';
import { LazyLoadImage, trackWindowScroll }
from 'react-lazy-load-image-component';
import { config } from '../store';
import { Row, Col } from 'antd';
const Gallery = ({ images, imageSize,addElementRef,selectPhoto,getStyle, scrollPosition }) => (
<Row gutter={[16, 16]}>
{images.map((image, index) =>
<Col key={image.id} span={parseInt(imageSize)}>
<div
//ref={addElementRef}
className={`item`}
>
<figure className="galleryImg" style={getStyle(image.id)} onClick={(e) => selectPhoto(e, image)}>
<LazyLoadImage
alt={image.name}
// Make sure to pass down the scrollPosition,
// this will be used by the component to know
// whether it must track the scroll position or not
scrollPosition={scrollPosition}
src={config.imageUrl + image.id + "?size=tiny&token=" + localStorage.getItem('token')}
width="100%"
height="100%"
/>
</figure>
</div>
</Col>
)}
</Row>
);
import "./loading/loading.css"
import Loading from './loading/loading.svg';
import { config } from '../store';
const Gallery = ({ images, imageSize, addElementRef, selectPhoto, getStyle, scrollPosition }) => {

const spanWidth = (size) => {
console.log("CHANGE_SIZE", size)
switch (size) {
case "xsmall":
return 2;
case "small":
return 4;
case "medium":
return 6;
case "large":
return 12;
case "xlarge":
return 24;
default: return 2;
}
}
return (
<Row gutter={[16, 16]}>
{images.map((image, index) =>
<Col key={image.id} span={spanWidth(imageSize)}>
<div
//ref={addElementRef}
className={`item`}
>
<figure className="galleryImg" style={getStyle(image.id)} onClick={(e) => selectPhoto(e, image)}>
<LazyLoadImage
alt={image.name}
effect="blur"
scrollPosition={scrollPosition}
src={config.imageUrl + image.id + "?size=" + imageSize}
wrapperProps={
{
style:{
backgroundSize:"30% 30%",
backgroundRepeat:"no-repeat",
backgroundPosition:"center",
backgroundImage:`url(${Loading})`,
color: "transparent",
display: "inline-block",
height: "100%",
width: "100%",
border: "1px solid white",
borderRadius: "0px"
}
}
}
width="100%"
height="100%"
style={{objectFit:"cover"}}
/>
</figure>
</div>
</Col>
)}
</Row>
);
}
// Wrap Gallery with trackWindowScroll HOC so it receives
// a scrollPosition prop to pass down to the images
export default trackWindowScroll(Gallery);
Expand Down
15 changes: 0 additions & 15 deletions frontend/src/components/Lazyloading.jsx

This file was deleted.

39 changes: 39 additions & 0 deletions frontend/src/components/loading/loading.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.container {
--uib-size: 35px;
--uib-color: black;
--uib-speed: 1.2s;
--uib-bg-opacity: .1;
height: var(--uib-size);
width: var(--uib-size);
transform-origin: center;
will-change: transform;
overflow: visible;
}

.car {
fill: none;
stroke: var(--uib-color);
stroke-dasharray: 25, 75;
stroke-dashoffset: 0;
animation: travel var(--uib-speed) linear infinite;
will-change: stroke-dasharray, stroke-dashoffset;
transition: stroke 0.5s ease;
}

.track {
fill: none;
stroke: var(--uib-color);
opacity: var(--uib-bg-opacity);
transition: stroke 0.5s ease;
}

@keyframes travel {
0% {
stroke-dashoffset: 0;
}

100% {
stroke-dashoffset: -100;
}
}

30 changes: 30 additions & 0 deletions frontend/src/components/loading/loading.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import "./loading.css"

export const Loading = () => (
<svg
className="container"
viewBox="0 0 35 35"
height="35"
width="35"
>
<rect
className="track"
x="2.5"
y="2.5"
fill="none"
stroke-width="5px"
width="32.5"
height="32.5"
/>
<rect
className="car"
x="2.5"
y="2.5"
fill="none"
stroke-width="5px"
width="32.5"
height="32.5"
pathlength="100"
/>
</svg>
)
9 changes: 9 additions & 0 deletions frontend/src/components/loading/loading.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/components/loading/placeholder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 2 additions & 4 deletions frontend/src/components/sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ const SideBar = ({ photo }) => {
return date.toLocaleString();
}



return (
<Sider width={data.name ? 350 : 0} style={{ overflow: "auto", height: "calc(100vh - 64px)" }}>
<img src={config.imageUrl + data.id + "?size=tiny&token=" + localStorage.getItem('token')} width="100%" alt="thumbnail" />
<Sider width={data.name ? 500 : 0} style={{ overflow: "auto", height: "calc(100vh - 64px)" }}>
<img src={config.imageUrl + data.id + "?size=small"} width="100%" alt="thumbnail" />
<Form
form={form}
layout="horizontal"
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/pages/Main.css
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,14 @@ html, body {
.brand {
float: left;
font-size: 24px;
padding: 0px 44px;
color: white;
border-right: 1px solid #282828;
border-color: rgba(253, 253, 253, 0.12);
width: 200px;
text-align: center;
}


.brand:hover {
color: rgba(255, 255, 255, 0.65);
}
Expand Down
Loading

0 comments on commit a6ad8bd

Please sign in to comment.