Skip to content

Commit

Permalink
Fix thumbnail sync conflict on first edit after creation
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmarreirosdeoliveira committed Apr 11, 2018
1 parent ff9bb1a commit 54115f0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions app/components/imageupload/image-uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {UploadStatus} from './upload-status';
import {PersistenceManager} from '../../core/persist/persistence-manager';
import {DocumentReadDatastore} from '../../core/datastore/document-read-datastore';
import {NewIdaiFieldImageDocument} from "../../core/model/new-idai-field-image-document";
import {IdaiFieldImageDocumentReadDatastore} from '../../core/datastore/field/idai-field-image-document-read-datastore';

export interface ImageUploadResult {

Expand All @@ -37,7 +38,8 @@ export class ImageUploader {
private persistenceManager: PersistenceManager,
private projectConfiguration: ProjectConfiguration,
private settingsService: SettingsService,
private uploadStatus: UploadStatus
private uploadStatus: UploadStatus,
private imageDocumentDatastore: IdaiFieldImageDocumentReadDatastore
) {}


Expand Down Expand Up @@ -158,8 +160,13 @@ export class ImageUploader {
reader.onloadend = (that => {
return () => {
that.createImageDocument(file, type, depictsRelationTarget)
.then(doc => that.imagestore.create(doc.resource.id, reader.result, true))
.then(() => resolve())
.then(doc => that.imagestore.create(doc.resource.id, reader.result, true).then(() =>
// to refresh the thumbnail in cache, which is done to prevent a conflict afterwards
this.imageDocumentDatastore.get(doc.resource.id, { skip_cache: true })
))
.then(() =>
resolve()
)
.catch(error => {
console.error(error);
reject([M.IMAGESTORE_ERROR_WRITE, file.name]);
Expand Down

0 comments on commit 54115f0

Please sign in to comment.